aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/qqmlimport.cpp18
-rw-r--r--src/qml/qml/qqmlimport_p.h5
-rw-r--r--tests/auto/qml/qqmllanguage/data/inlineComponentFoundBeforeOtherImports.qml9
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp11
4 files changed, 43 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 2a6ede83c7..c3f6a9057d 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -988,6 +988,12 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
if (!typeRecursionDetected)
typeRecursionDetected = &localTypeRecursionDetected;
+ if (needsSorting()) {
+ std::stable_sort(imports.begin(), imports.end(), [](QQmlImportInstance *left, QQmlImportInstance *) {
+ return left->isInlineComponent;
+ });
+ setNeedsSorting(false);
+ }
for (int i=0; i<imports.count(); ++i) {
const QQmlImportInstance *import = imports.at(i);
if (import->resolveType(typeLoader, type, vmajor, vminor, type_return, base,
@@ -1047,6 +1053,17 @@ bool QQmlImportNamespace::resolveType(QQmlTypeLoader *typeLoader, const QHashedS
return false;
}
+bool QQmlImportNamespace::needsSorting() const
+{
+ return nextNamespace == this;
+}
+
+void QQmlImportNamespace::setNeedsSorting(bool needsSorting)
+{
+ Q_ASSERT(nextNamespace == this || nextNamespace == nullptr);
+ nextNamespace = needsSorting ? this : nullptr;
+}
+
QQmlImportsPrivate::QQmlImportsPrivate(QQmlTypeLoader *loader)
: ref(1), typeLoader(loader) {
}
@@ -1760,6 +1777,7 @@ bool QQmlImports::addInlineComponentImport(QQmlImportInstance *const importInsta
importInstance->minversion = 0;
importInstance->containingType = containingType;
d->unqualifiedset.imports.push_back(importInstance);
+ d->unqualifiedset.setNeedsSorting(true);
return true;
}
diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h
index 2e994fd27f..594eae7bb4 100644
--- a/src/qml/qml/qqmlimport_p.h
+++ b/src/qml/qml/qqmlimport_p.h
@@ -122,7 +122,12 @@ public:
QHashedString prefix;
// Used by QQmlImportsPrivate::qualifiedSets
+ // set to this in unqualifiedSet to indicate that the lists of imports needs
+ // to be sorted when an inline component import was added
+ // We can't use flag pointer, as that does not work with QFieldList
QQmlImportNamespace *nextNamespace;
+ bool needsSorting() const;
+ void setNeedsSorting(bool needsSorting);
};
class Q_QML_PRIVATE_EXPORT QQmlImports
diff --git a/tests/auto/qml/qqmllanguage/data/inlineComponentFoundBeforeOtherImports.qml b/tests/auto/qml/qqmllanguage/data/inlineComponentFoundBeforeOtherImports.qml
new file mode 100644
index 0000000000..85903727fb
--- /dev/null
+++ b/tests/auto/qml/qqmllanguage/data/inlineComponentFoundBeforeOtherImports.qml
@@ -0,0 +1,9 @@
+import QtQuick 2.12
+
+Item
+{
+ component Rectangle: Item {
+ Component.onCompleted: console.info("Created")
+ }
+ Rectangle {}
+}
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 4d4056ba3f..bc2b7169d0 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -318,6 +318,7 @@ private slots:
void inlineComponentInSingleton();
void nonExistingInlineComponent_data();
void nonExistingInlineComponent();
+ void inlineComponentFoundBeforeOtherImports();
void selfReference();
void selfReferencingSingleton();
@@ -5663,6 +5664,16 @@ void tst_qqmllanguage::nonExistingInlineComponent()
QCOMPARE(error.column(), column);
}
+void tst_qqmllanguage::inlineComponentFoundBeforeOtherImports()
+{
+ QQmlEngine engine;
+ QUrl url = testFileUrl("inlineComponentFoundBeforeOtherImports.qml");
+ QQmlComponent component(&engine, url);
+
+ QTest::ignoreMessage(QtMsgType::QtInfoMsg, "Created");
+ QScopedPointer<QObject> root {component.create()};
+}
+
class TestItem : public QObject
{
Q_OBJECT