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:26 +0000 |
commit | 25e26270a1ec0ed838f009d8694f3507af1b0554 (patch) | |
tree | 855a85f0802b3489d02ddcab2c48f534ce4c8ad0 | |
parent | c19e529d5513a46a91d25117e57ff5e461731259 (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>
-rw-r--r-- | src/qml/qml/qqmlincubator.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp | 33 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp index 6a0210c153..7d4ffcec3f 100644 --- a/src/qml/qml/qqmlincubator.cpp +++ b/src/qml/qml/qqmlincubator.cpp @@ -331,7 +331,7 @@ void QQmlIncubatorPrivate::incubate(QQmlInstantiationInterrupt &i) ddata->rootObjectInCreation = false; if (q) { q->setInitialState(result); - if (!creator->requiredProperties().empty()) { + if (creator && !creator->requiredProperties().empty()) { const auto& unsetRequiredProperties = creator->requiredProperties(); for (const auto& unsetRequiredProperty: unsetRequiredProperties) errors << QQmlComponentPrivate::unsetRequiredPropertyToQQmlError(unsetRequiredProperty); 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" |