diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-02-16 15:49:37 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-19 08:54:26 +0000 |
commit | dae0fe461b26b6db85586db1979bc1d9fb05670b (patch) | |
tree | 56ce78ff0dbc6951e4ab45cf5d182aad0662a943 | |
parent | aa90901c4f1873b325580fff8c201e17826d2eaa (diff) |
QQmlPropertyPrivate::signalExpression: handle object being null
QQmlData::get expects a non-null pointer, therefore we need to check
whether the object still exists.
Note that while this fixes the crash in the referenced bug,
PropertyChanges still does not support a dynamic target.
Task-number: QTBUG-46350
Change-Id: Ifeecf5df83e87468a1d314ce2b120006124d6f4b
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
(cherry picked from commit 1ff376e64bf5af6df7e0079700d2b9164037dc89)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qml/qml/qqmlproperty.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp index 68127f8686..0ab36c205c 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -920,6 +920,8 @@ QQmlPropertyPrivate::signalExpression(const QQmlProperty &that) if (!(that.type() & QQmlProperty::SignalProperty)) return nullptr; + if (!that.d->object) + return nullptr; QQmlData *data = QQmlData::get(that.d->object); if (!data) return nullptr; @@ -959,6 +961,8 @@ void QQmlPropertyPrivate::takeSignalExpression(const QQmlProperty &that, return; } + if (!that.d->object) + return; QQmlData *data = QQmlData::get(that.d->object, nullptr != expr); if (!data) return; diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 7177089d7c..4968d4e97f 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -195,6 +195,8 @@ private slots: void nestedQQmlPropertyMap(); void underscorePropertyChangeHandler(); + + void signalExpressionWithoutObject(); private: QQmlEngine engine; }; @@ -2263,6 +2265,14 @@ void tst_qqmlproperty::underscorePropertyChangeHandler() QVERIFY(changeHandler.isSignalProperty()); } +void tst_qqmlproperty::signalExpressionWithoutObject() +{ + QQmlProperty invalid; + QQmlPropertyPrivate::setSignalExpression(invalid, nullptr); + QQmlBoundSignalExpression *expr = QQmlPropertyPrivate::signalExpression(invalid); + QVERIFY(!expr); +} + QTEST_MAIN(tst_qqmlproperty) #include "tst_qqmlproperty.moc" |