diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-02-28 15:28:34 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-03-01 12:37:40 +0000 |
commit | 9e14afa9a034e6cf9e34e1e81d6b0cc7509d7568 (patch) | |
tree | 420041ce985afe9f73d0ff4773a8055f8c6475f0 /tests | |
parent | e215241b32753d4c1181a0069951ab7c7993acd1 (diff) |
QQuickLoader: Check for QQmlEngine before using it
The loader's context may have been removed from the context hierarchy or
it may not have a context in the first place. We should not crash then.
Fixes: QTBUG-67950
Change-Id: I1058d5b1f978aa040f8b2f018c4357dd7a3ef333
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 79e885537f8546a18d7d9d902d6efe40b1915c96)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickloader/data/noEngine.qml | 32 | ||||
-rw-r--r-- | tests/auto/quick/qquickloader/tst_qquickloader.cpp | 15 |
2 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickloader/data/noEngine.qml b/tests/auto/quick/qquickloader/data/noEngine.qml new file mode 100644 index 0000000000..19e619f32e --- /dev/null +++ b/tests/auto/quick/qquickloader/data/noEngine.qml @@ -0,0 +1,32 @@ +import QtQuick 2 + +Item { + id: root + property bool a: false + property int changes: 0 + onAChanged: { + m.model = 0 + m.model = 1 + ++changes; + } + + Repeater { + id: m + model: 1 + + Item { + Timer { + onTriggered: { + root.a = true + l.source = "loaded.qml" + } + interval: 0 + running: true + } + + Loader { + id: l + } + } + } +} diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index cf1c4fcce0..e990e94bc3 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -134,6 +134,7 @@ private slots: void setSourceAndCheckStatus(); void asyncLoaderRace(); + void noEngine(); }; Q_DECLARE_METATYPE(QList<QQmlError>) @@ -1533,6 +1534,20 @@ void tst_QQuickLoader::asyncLoaderRace() QCOMPARE(loader->item(), nullptr); } +void tst_QQuickLoader::noEngine() +{ + QQmlEngine engine; + const QUrl url = testFileUrl("noEngine.qml"); + QQmlComponent component(&engine, url); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> o(component.create()); + + const QString message = url.toString() + + QStringLiteral(":27:13: QML Loader: createComponent: Cannot find a QML engine."); + QTest::ignoreMessage(QtWarningMsg, qPrintable(message)); + QTRY_COMPARE(o->property("changes").toInt(), 1); +} + QTEST_MAIN(tst_QQuickLoader) #include "tst_qquickloader.moc" |