From 5c4be5351e9d3a741ea49af63d0248f1d46542e3 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 21 Mar 2022 10:48:38 +0100 Subject: [PATCH] QProperty: Allow manual scheduling of binding notification In some situation we want to notify even if the value didn't change. Task-number: QTBUG-101771 Change-Id: I7d82a9f6e0f7d5eb48065e3f428b814939181ea8 Reviewed-by: Fabian Kosmale (cherry picked from commit 908ee8aab1d9b5d022cadb23d23de56ca72570e9) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qproperty_p.h | 1 + .../corelib/kernel/qproperty/tst_qproperty.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/corelib/kernel/qproperty_p.h b/src/corelib/kernel/qproperty_p.h index fcae7117ef9..0b9d6f29f8c 100644 --- a/src/corelib/kernel/qproperty_p.h +++ b/src/corelib/kernel/qproperty_p.h @@ -242,6 +242,7 @@ public: bool isUpdating() {return updating;} void setSticky(bool keep = true) {m_sticky = keep;} bool isSticky() {return m_sticky;} + void scheduleNotify() {pendingNotify = true;} QPropertyBindingPrivate(QMetaType metaType, const QtPrivate::BindingFunctionVTable *vtable, const QPropertyBindingSourceLocation &location, bool isQQmlPropertyBinding=false) diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index b1cc37ab7af..080b673ac99 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -117,6 +117,7 @@ private slots: void selfBindingShouldNotCrash(); void qpropertyAlias(); + void scheduleNotify(); }; void tst_QProperty::functorBinding() @@ -1874,6 +1875,21 @@ void tst_QProperty::qpropertyAlias() QVERIFY(!alias.isValid()); } +void tst_QProperty::scheduleNotify() +{ + int notifications = 0; + QProperty p; + QCOMPARE(p.value(), 0); + const auto handler = p.addNotifier([&](){ ++notifications; }); + QCOMPARE(notifications, 0); + QPropertyBinding b([]() { return 0; }, QPropertyBindingSourceLocation()); + QPropertyBindingPrivate::get(b)->scheduleNotify(); + QCOMPARE(notifications, 0); + p.setBinding(b); + QCOMPARE(notifications, 1); + QCOMPARE(p.value(), 0); +} + QTEST_MAIN(tst_QProperty); #undef QT_SOURCE_LOCATION_NAMESPACE