diff options
4 files changed, 21 insertions, 0 deletions
diff --git a/src/qml/qml/qqmldatablob.cpp b/src/qml/qml/qqmldatablob.cpp index b22e46b69c..82e6fcf56c 100644 --- a/src/qml/qml/qqmldatablob.cpp +++ b/src/qml/qml/qqmldatablob.cpp @@ -359,6 +359,12 @@ void QQmlDataBlob::addDependency(QQmlDataBlob *blob) m_waitingFor.append(blob); blob->m_waitingOnMe.append(this); + + // Check circular dependency + if (m_waitingOnMe.indexOf(blob) >= 0) { + qWarning() << "Cyclic dependency detected between" << this->url().toString() << "and" << blob->url().toString(); + m_data.setStatus(Error); + } } /*! diff --git a/tests/auto/qml/qqmltypeloader/data/CircularDependency.qml b/tests/auto/qml/qqmltypeloader/data/CircularDependency.qml new file mode 100644 index 0000000000..0b7c030063 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/CircularDependency.qml @@ -0,0 +1,3 @@ +import QtQml 2.0 + +CircularDependencyBase {} diff --git a/tests/auto/qml/qqmltypeloader/data/CircularDependencyBase.qml b/tests/auto/qml/qqmltypeloader/data/CircularDependencyBase.qml new file mode 100644 index 0000000000..d068d1cabc --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/CircularDependencyBase.qml @@ -0,0 +1,3 @@ +import QtQml 2.0 + +CircularDependency {} diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index 266a4e97d6..1303a4b19c 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -63,6 +63,7 @@ private slots: void implicitImport(); void compositeSingletonCycle(); void declarativeCppType(); + void circularDependency(); }; void tst_QQMLTypeLoader::testLoadComplete() @@ -592,6 +593,14 @@ void tst_QQMLTypeLoader::declarativeCppType() QVERIFY(!obj.isNull()); } +void tst_QQMLTypeLoader::circularDependency() +{ + QQmlEngine engine; + QTest::ignoreMessage(QtWarningMsg, QRegularExpression("Cyclic dependency detected between (.*) and (.*)")); + QQmlComponent component(&engine, testFileUrl("CircularDependency.qml")); + QCOMPARE(component.status(), QQmlComponent::Null); +} + QTEST_MAIN(tst_QQMLTypeLoader) #include "tst_qqmltypeloader.moc" |