diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-03-01 15:34:58 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-03-04 09:30:21 +0000 |
commit | 6898e59357a0a5f7c3b369aa270a3338ffa78da7 (patch) | |
tree | 61c9b56785d06b2e9093e5c625594eb0906faa61 /tests | |
parent | 5ef7e0b285992120e3a1d32418fe19a2614e6e47 (diff) |
qqmlapplicationengine: Handle errors during component creation
Previously QQmlApplicationEngine did not handle any errors that occurred during object creation
(i.e. failures to initialize required properties) which lead to QObject::connect errors and to
the error messages not getting printed among other issues.
Change-Id: I69bc566a6d349c786cae82a963a621388684c8f5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 890cb4cb236333fd5b112fffc0e9088ecb43f2df)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
3 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlapplicationengine/data/Required.qml b/tests/auto/qml/qqmlapplicationengine/data/Required.qml new file mode 100644 index 0000000000..dd45902bef --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/data/Required.qml @@ -0,0 +1,6 @@ +import QtQml + +QtObject +{ + required property int foo +} diff --git a/tests/auto/qml/qqmlapplicationengine/data/requiredViolation.qml b/tests/auto/qml/qqmlapplicationengine/data/requiredViolation.qml new file mode 100644 index 0000000000..21c29ca6c2 --- /dev/null +++ b/tests/auto/qml/qqmlapplicationengine/data/requiredViolation.qml @@ -0,0 +1,3 @@ +import QtQml + +Required {} diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index f636e527c3..4306c7b8ca 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -56,6 +56,7 @@ private slots: void translationChange(); void setInitialProperties(); void failureToLoadTriggersWarningSignal(); + void errorWhileCreating(); private: QString buildDir; @@ -333,6 +334,23 @@ void tst_qqmlapplicationengine::failureToLoadTriggersWarningSignal() QTRY_COMPARE(warningObserver.count(), 1); } +void tst_qqmlapplicationengine::errorWhileCreating() +{ + auto url = testFileUrl("requiredViolation.qml"); + QQmlApplicationEngine test; + QSignalSpy observer(&test, &QQmlApplicationEngine::objectCreated); + + QTest::ignoreMessage(QtMsgType::QtWarningMsg, "QQmlApplicationEngine failed to create component"); + QTest::ignoreMessage(QtMsgType::QtWarningMsg, qPrintable(QStringLiteral("%1:5:5: Required property foo was not initialized").arg(testFileUrl("Required.qml").toString()))); + + test.load(url); + + QTRY_COMPARE(observer.count(), 1); + QList<QVariant> args = observer.takeFirst(); + QVERIFY(args.at(0).isNull()); + QCOMPARE(args.at(1).toUrl(), url); +} + QTEST_MAIN(tst_qqmlapplicationengine) #include "tst_qqmlapplicationengine.moc" |