aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlproperty
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2019-07-22 13:41:11 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2019-07-22 16:00:52 +0200
commitda14688140550879e376e71cf273b16494e6c3c4 (patch)
tree6f7e77721b1277f4039ea1e7dd0c64d5f81fefab /tests/auto/qml/qqmlproperty
parentb0e19e1d08e17a7fd76008447be0f788ebf73f1f (diff)
Fix nullptr handling in binding
Fixes: QTBUG-77027 Change-Id: I61d5a20329ffe95af810b89e338eee2bc10bfe04 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlproperty')
-rw-r--r--tests/auto/qml/qqmlproperty/data/nullPropertyBinding.qml22
-rw-r--r--tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp17
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlproperty/data/nullPropertyBinding.qml b/tests/auto/qml/qqmlproperty/data/nullPropertyBinding.qml
new file mode 100644
index 0000000000..4fffc7aead
--- /dev/null
+++ b/tests/auto/qml/qqmlproperty/data/nullPropertyBinding.qml
@@ -0,0 +1,22 @@
+import QtQuick 2.12
+
+Item {
+ id: root
+
+ width: 640
+ height: 480
+
+ property bool toggle: false
+ property Item bound
+ property string message: "defined"
+
+ readonly property Item item: root.toggle ? root : null
+
+ Binding { target: root; property: "bound"; value: item}
+
+ function tog() {
+ console.info(root.bound ? root.bound.message: "undefined")
+ root.toggle = !root.toggle
+ return 42;
+ }
+}
diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
index 04c61ec11b..67da768f73 100644
--- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
+++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
@@ -144,6 +144,7 @@ private slots:
void deeplyNestedObject();
void readOnlyDynamicProperties();
void aliasToIdWithMatchingQmlFileNameOnCaseInsensitiveFileSystem();
+ void nullPropertyBinding();
void floatToStringPrecision_data();
void floatToStringPrecision();
@@ -2059,6 +2060,22 @@ void tst_qqmlproperty::aliasToIdWithMatchingQmlFileNameOnCaseInsensitiveFileSyst
QVERIFY(property.isValid());
}
+// QTBUG-77027
+void tst_qqmlproperty::nullPropertyBinding()
+{
+ const QUrl url = testFileUrl("nullPropertyBinding.qml");
+ QQmlEngine engine;
+ QQmlComponent component(&engine, url);
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(root);
+ QTest::ignoreMessage(QtMsgType::QtInfoMsg, "undefined");
+ QMetaObject::invokeMethod(root.get(), "tog");
+ QTest::ignoreMessage(QtMsgType::QtInfoMsg, "defined");
+ QMetaObject::invokeMethod(root.get(), "tog");
+ QTest::ignoreMessage(QtMsgType::QtInfoMsg, "undefined");
+ QMetaObject::invokeMethod(root.get(), "tog");
+}
+
void tst_qqmlproperty::floatToStringPrecision_data()
{
QTest::addColumn<QString>("propertyName");