diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-03-17 15:20:09 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-03-30 06:51:17 +0000 |
commit | 63712d9f9d236cd126c8a017c4779f270aff5d69 (patch) | |
tree | 89394f1751cd3d10f9d490b6373ac2262b860fbe /tests/auto/quick/qquickbehaviors | |
parent | 7e5942447bf3ba28343474e23e42e87e57d5cdb9 (diff) |
QQuickBehavior: Force notify when first setting the binding
If the binding on the proxy property results in the default value of the
type, we still want to set the original property with that value.
Fixes: QTBUG-101771
Change-Id: Ia289eb734288a4bcc02444fcb73781a57216c908
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit aa4e5d598248008f8490eef07288f60af6f77900)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/qquickbehaviors')
-rw-r--r-- | tests/auto/quick/qquickbehaviors/data/defaultQProperty.qml | 14 | ||||
-rw-r--r-- | tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp | 18 |
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickbehaviors/data/defaultQProperty.qml b/tests/auto/quick/qquickbehaviors/data/defaultQProperty.qml new file mode 100644 index 0000000000..596efac325 --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/defaultQProperty.qml @@ -0,0 +1,14 @@ +import QtQuick + +Item { + property int heightChanges: 0 + property int widthChanges: 0 + implicitWidth: 50 + implicitHeight: 50 + height: { return 0 } + width: { return 10 } + Behavior on height { NumberAnimation { duration: 300 } } + Behavior on width { NumberAnimation { duration: 300 } } + onHeightChanged: ++heightChanges + onWidthChanged: ++widthChanges +} diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index d1bbdcbd66..159fb1398e 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -78,6 +78,7 @@ private slots: void safeToDelete(); void targetProperty(); void bindableProperty(); + void defaultQProperty(); }; void tst_qquickbehaviors::simpleBehavior() @@ -703,6 +704,23 @@ void tst_qquickbehaviors::bindableProperty() QTRY_COMPARE(testBindable->prop(), 300); } +void tst_qquickbehaviors::defaultQProperty() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("defaultQProperty.qml")); + QScopedPointer<QObject> root(c.create()); + QVERIFY2(root, qPrintable(c.errorString())); + + QQuickItem *item = qobject_cast<QQuickItem *>(root.data()); + QVERIFY(item); + + QCOMPARE(item->height(), 0.0); + QCOMPARE(item->width(), 10.0); + + // Both change only once: No intermediate change to 0 on width. + QCOMPARE(root->property("heightChanges").toInt(), 1); + QCOMPARE(root->property("widthChanges").toInt(), 1); +} QTEST_MAIN(tst_qquickbehaviors) |