diff options
-rw-r--r-- | src/qml/qml/qqmlengine.cpp | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/SingletonTest.qml | 14 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/qmldir | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/qtbug_85932.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 22 |
5 files changed, 49 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlengine.cpp b/src/qml/qml/qqmlengine.cpp index ef9fec56fb..5a20b93c2c 100644 --- a/src/qml/qml/qqmlengine.cpp +++ b/src/qml/qml/qqmlengine.cpp @@ -2391,6 +2391,12 @@ QJSValue QQmlEnginePrivate::singletonInstance<QJSValue>(const QQmlType &type) singletonInstances.convertAndInsert(v4engine(), type, &value); } else if (!siinfo->url.isEmpty()) { QQmlComponent component(q, siinfo->url, QQmlComponent::PreferSynchronous); + if (component.isError()) { + warning(component.errors()); + v4engine()->throwError(QLatin1String("Due to the preceding error(s), Singleton \"%1\" could not be loaded.").arg(QString::fromUtf8(type.typeName()))); + + return QJSValue(QJSValue::UndefinedValue); + } QObject *o = component.beginCreate(q->rootContext()); value = q->newQObject(o); singletonInstances.convertAndInsert(v4engine(), type, &value); diff --git a/tests/auto/qml/qqmllanguage/data/SingletonTest.qml b/tests/auto/qml/qqmllanguage/data/SingletonTest.qml new file mode 100644 index 0000000000..70e1671754 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/SingletonTest.qml @@ -0,0 +1,14 @@ +pragma Singleton + +import QtQml 2.0 + +// This causes a duplicate id error on purpose +QtObject { + id: foo + + QtObject { + id: foo + } + + function test() { return "Foobar"; } +} diff --git a/tests/auto/qml/qqmllanguage/data/qmldir b/tests/auto/qml/qqmllanguage/data/qmldir new file mode 100644 index 0000000000..c946de657c --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/qmldir @@ -0,0 +1,2 @@ +singleton SingletonTest 1.0 SingletonTest.qml + diff --git a/tests/auto/qml/qqmllanguage/data/qtbug_85932.qml b/tests/auto/qml/qqmllanguage/data/qtbug_85932.qml new file mode 100644 index 0000000000..aa21558220 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/qtbug_85932.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + Component.onCompleted: console.log(SingletonTest.test()) +} diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 448ecaa5b3..4f4ee45f68 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -344,6 +344,7 @@ private slots: void extendedNamespace(); void factorySingleton(); void extendedSingleton(); + void qtbug_85932(); private: QQmlEngine engine; @@ -6095,6 +6096,27 @@ void tst_qqmllanguage::extendedSingleton() QCOMPARE(obj->property("d").toInt(), 9); } +void tst_qqmllanguage::qtbug_85932() +{ + QString warning1 = QLatin1String("%1:10:9: id is not unique").arg(testFileUrl("SingletonTest.qml").toString()); + QString warning2 = QLatin1String("%1:4: Error: Due to the preceding error(s), Singleton \"SingletonTest\" could not be loaded.").arg(testFileUrl("qtbug_85932.qml").toString()); + + QTest::ignoreMessage(QtMsgType::QtWarningMsg, qPrintable(warning1)); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, qPrintable(warning2)); + + QQmlEngine engine; + QList<QQmlError> allWarnings; + QObject::connect(&engine, &QQmlEngine::warnings, [&allWarnings](const QList<QQmlError> &warnings) { + allWarnings.append(warnings); + }); + + QQmlComponent c(&engine, testFileUrl("qtbug_85932.qml")); + QScopedPointer<QObject> obj(c.create()); + QTRY_COMPARE(allWarnings.count(), 2); + QCOMPARE(allWarnings.at(0).toString(), warning1); + QCOMPARE(allWarnings.at(1).toString(), warning2); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" |