diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-04-11 15:18:10 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2022-06-08 18:10:36 +0200 |
commit | e70d6e6b4543d91dc9b4eac466146bde1487ba6f (patch) | |
tree | db38857c60716aa53d10ac2e428e72a0a494feb0 | |
parent | 00821ec4d5de95eaa1e6f86b99b59339d3dd2225 (diff) |
Immediately complete component upon creation failure
We do not want to wait until reaching the Component destructor (at which
point e.g. the engine might be gone).
Change-Id: Ic0e4383ec4e3759d9f02847413a25191a01286cb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 759090f59140d0b38c7bd57480ea6cd93d4cf0d3)
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 3 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index addee70b6b..f54eee3e72 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -862,8 +862,16 @@ QObject *QQmlComponent::create(QQmlContext *context) Q_D(QQmlComponent); QObject *rv = d->doBeginCreate(this, context); - if (rv) + if (rv) { completeCreate(); + } else if (d->state.completePending) { + // overridden completCreate might assume that + // the object has actually been created + ++creationDepth.localData(); + QQmlEnginePrivate *ep = QQmlEnginePrivate::get(d->engine); + d->complete(ep, &d->state); + --creationDepth.localData(); + } if (rv && !d->requiredProperties().empty()) { delete rv; return nullptr; diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index b25dec67f1..ab23f71f3e 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -4418,9 +4418,6 @@ void tst_qqmllanguage::deepProperty() void tst_qqmllanguage::groupAssignmentFailure() { auto ep = std::make_unique<QQmlEngine>(); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, "QQmlComponent: Component destroyed while completion pending"); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, "This may have been caused by one of the following errors:"); - QTest::ignoreMessage(QtMsgType::QtWarningMsg, QRegularExpression(".*Cannot set properties on b as it is null.*")); QTest::ignoreMessage(QtMsgType::QtWarningMsg, QRegularExpression(".*Invalid property assignment: url expected - Assigning null to incompatible properties in QML is deprecated. This will become a compile error in future versions of Qt..*")); QQmlComponent component(ep.get(), testFileUrl("groupFailure.qml")); QScopedPointer<QObject> o(component.create()); |