From 36fc392147ea79bb665058ea165c86f6cd6680d7 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 24 Mar 2020 21:03:05 +0100 Subject: Implement support for property observers Syntactically we call them signal handler expressions :-), now also working when the underlying property doesn't emit an old-style signal but is just a QProperty. Change-Id: I719a3e428f44af0fd48036434aefa682a02f7de1 Reviewed-by: Fabian Kosmale --- tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml | 4 ++++ tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 3 +++ 2 files changed, 7 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml b/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml index 1bd043d9df..2be07f35ae 100644 --- a/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml +++ b/tests/auto/qml/qqmlecmascript/data/bindingOnQProperty.qml @@ -4,4 +4,8 @@ ClassWithQProperty { value: { return externalValue } + property int changeHandlerCount: 0 + onValueChanged: { + changeHandlerCount++; + } } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 2a23d7ec60..fc50c2a09f 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -9288,8 +9288,11 @@ void tst_qqmlecmascript::bindingOnQProperty() QScopedPointer test(component.create()); test->setProperty("externalValue", 42); QCOMPARE(test->property("value").toInt(), 42); + // Value hasn't changed yet... + QCOMPARE(test->property("changeHandlerCount").toInt(), 0); test->setProperty("externalValue", 100); QCOMPARE(test->property("value").toInt(), 100); + QCOMPARE(test->property("changeHandlerCount").toInt(), 1); QVERIFY(qobject_cast(test.data())); QProperty &qprop = static_cast(test.data())->value; -- cgit v1.2.3