diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-03 16:12:07 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-03-04 11:53:25 +0000 |
commit | e1ab5c04c731d26af586a927321fe94413b88c89 (patch) | |
tree | f9a2353e2d419c56a4a3f552d846675ec141622d /tests | |
parent | 6898e59357a0a5f7c3b369aa270a3338ffa78da7 (diff) |
QQmlIncubator: handle clear inside setinitialState
Fixes: QTBUG-91519
Change-Id: Idfe3116c2e94b8e96300d72e15db0bc78425f517
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 2cb306c194625626957fcde44bd56473b0436f83)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp index 1650a3a1d6..ac26e8d9f3 100644 --- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp +++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp @@ -71,6 +71,7 @@ private slots: void contextDelete(); void garbageCollection(); void requiredProperties(); + void deleteInSetInitialState(); private: QQmlIncubationController controller; @@ -1232,6 +1233,38 @@ void tst_qqmlincubator::requiredProperties() } } +class DeletingIncubator : public QQmlIncubator +{ + + + // QQmlIncubator interface +protected: + void statusChanged(Status) override + { + + } + void setInitialState(QObject *obj) override + { + delete obj; + clear(); + } +}; + +void tst_qqmlincubator::deleteInSetInitialState() +{ + QQmlComponent component(&engine, testFileUrl("requiredProperty.qml")); + QVERIFY(component.isReady()); + // forceCompletion immediately after creating an asynchronous object completes it + DeletingIncubator incubator; + incubator.setInitialProperties({{"requiredProperty", 42}}); + QVERIFY(incubator.isNull()); + component.create(incubator); + QVERIFY(incubator.isLoading()); + incubator.forceCompletion(); // no crash + QVERIFY(incubator.isNull()); + QCOMPARE(incubator.object(), nullptr); // object was deleted +} + QTEST_MAIN(tst_qqmlincubator) #include "tst_qqmlincubator.moc" |