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.

Pick-to: 5.12 5.15 6.0 6.1
Task-number: QTBUG-46350
Change-Id: Ifeecf5df83e87468a1d314ce2b120006124d6f4b
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Fabian Kosmale 2021-02-16 15:49:37 +01:00
parent 3670395af5
commit 1ff376e64b
2 changed files with 14 additions and 0 deletions

View File

@ -922,6 +922,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;
@ -961,6 +963,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;

View File

@ -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"