aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-03-03 16:12:07 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-04 12:23:24 +0000
commitd43b92b0a91daefde95f3fa9bf8aad94412d19f3 (patch)
treeb6a72d3a1bd31046d8a4ee385ddd101c973a2020
parent1893c53117ffd3317ada82bcbbc9068410885713 (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.cpp2
-rw-r--r--tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp33
2 files changed, 34 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp
index f7cdbda01c..caf419b778 100644
--- a/src/qml/qml/qqmlincubator.cpp
+++ b/src/qml/qml/qqmlincubator.cpp
@@ -330,7 +330,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 549aae8c2b..25adf4f31d 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;
@@ -1213,6 +1214,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"