aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-07-09 17:22:36 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-07-12 10:14:10 +0000
commitb91da50429e95efc6f49b03b78ddbbfc538b7306 (patch)
tree6ca62db11664d425ddd408b2b549ad0d60030adc /src
parentd7ee847bd6260367de35632235a449efedba698e (diff)
QtQml: Look for existing imports even without redirection
It makes no sense to prohibit multiple imports of the same QML module with the same version. We can just re-order the imports according to prcedence when we detect this. Pick-to: 6.8 Fixes: QTBUG-138391 Change-Id: I5ad94e1181f6a2beb278e421c1bbf06678fd863b Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> (cherry picked from commit 8a29649cb79b258efbe918d92c7f78f07d535282) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> (cherry picked from commit 783e0399917675b22df124c7a4d5bd5823825a96)
Diffstat (limited to 'src')
-rw-r--r--src/qml/qml/qqmlimport.cpp39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index a305b8cecb..d869d1c043 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -1139,6 +1139,19 @@ QQmlImportNamespace *QQmlImports::importNamespace(const QString &prefix)
return nameSpace;
}
+static void insertImport(QQmlImportNamespace *nameSpace, QQmlImportInstance *import)
+{
+ for (auto it = nameSpace->imports.cbegin(), end = nameSpace->imports.cend();
+ it != end; ++it) {
+ if ((*it)->precedence < import->precedence)
+ continue;
+
+ nameSpace->imports.insert(it, import);
+ return;
+ }
+ nameSpace->imports.append(import);
+}
+
static QQmlImportInstance *addImportToNamespace(
QQmlImportNamespace *nameSpace, const QString &uri, const QString &url, QTypeRevision version,
QV4::CompiledData::Import::ImportType type, QList<QQmlError> *errors, quint16 precedence)
@@ -1156,15 +1169,7 @@ static QQmlImportInstance *addImportToNamespace(
import->precedence = precedence;
import->implicitlyImported = precedence >= QQmlImportInstance::Implicit;
- for (auto it = nameSpace->imports.cbegin(), end = nameSpace->imports.cend();
- it != end; ++it) {
- if ((*it)->precedence < precedence)
- continue;
-
- nameSpace->imports.insert(it, import);
- return import;
- }
- nameSpace->imports.append(import);
+ insertImport(nameSpace, import);
return import;
}
@@ -1267,15 +1272,23 @@ QTypeRevision QQmlImports::addLibraryImport(
if (qmldir.hasRedirection()) {
resolvedUrl = redirectQmldirContent(typeLoader, &qmldir);
resolvedUri = qmldir.typeNamespace();
- if (QQmlImportInstance *existing
- = nameSpace->findImportByLocation(resolvedUrl, requestedVersion)) {
- return finalizeLibraryImport(uri, importedVersion, qmldir, existing, errors);
- }
} else {
resolvedUrl = qmldirUrl;
resolvedUri = uri;
}
+ if (QQmlImportInstance *existing
+ = nameSpace->findImportByLocation(resolvedUrl, requestedVersion);
+ existing && existing->isLibrary && existing->uri == resolvedUri) {
+ // Even if the precedence stays the same we have to re-insert. The ordering wrt other
+ // imports of the same precendence may change.
+ nameSpace->imports.removeOne(existing);
+ existing->precedence = std::min(quint8(precedence), existing->precedence);
+ existing->implicitlyImported = existing->precedence >= QQmlImportInstance::Implicit;
+ insertImport(nameSpace, existing);
+ return finalizeLibraryImport(uri, importedVersion, qmldir, existing, errors);
+ }
+
QQmlImportInstance *inserted = addImportToNamespace(
nameSpace, resolvedUri, resolvedUrl, requestedVersion,
QV4::CompiledData::Import::ImportLibrary, errors,