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 09:23:50 +0000 |
commit | 689b323782eb24b8084ba9712897682932ff4908 (patch) | |
tree | 5b3df4a6e6a9b684ecd2d770d0d2470384f245f7 | |
parent | 69ae7eb1abee9e8d212c7277076285fe15a47f08 (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 f9c28ad54a..54e17cdf12 100644 --- a/src/qml/qml/qqmlproperty.cpp +++ b/src/qml/qml/qqmlproperty.cpp @@ -918,6 +918,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; @@ -957,6 +959,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 8a96fc52c5..5363cc8fcb 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -164,6 +164,8 @@ private slots: void nestedQQmlPropertyMap(); void underscorePropertyChangeHandler(); + + void signalExpressionWithoutObject(); private: QQmlEngine engine; }; @@ -2210,6 +2212,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" |