summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-04-20 11:00:46 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-04-22 16:15:41 +0200
commitcdabe1d64c1ac3f99aa23be873daa45042f957cf (patch)
treee7eb1b8a1baf5cefc08e099b61e355e056ba49a6 /tests
parentd558ebf79b76e1a428a350d28950813a4db0755d (diff)
QObjectBindableProperty: Allow signals taking a value
If the signal takes a value, we pass the current value of the property to it. As we now use eager evaluation, accessing the current value is now possible. Change-Id: I5e6947a6575bfa8ca5143f56620c645d4750a686 Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 5197be3912..6d28fd6747 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -83,6 +83,7 @@ private slots:
void quntypedBindableApi();
void readonlyConstQBindable();
void qobjectBindableManualNotify();
+ void qobjectBindableSignalTakingNewValue();
void testNewStuff();
void qobjectObservers();
@@ -1088,7 +1089,7 @@ class MyQObject : public QObject
Q_PROPERTY(int compat READ compat WRITE setCompat NOTIFY compatChanged)
signals:
- void fooChanged();
+ void fooChanged(int newFoo);
void barChanged();
void compatChanged();
@@ -1182,6 +1183,28 @@ void tst_QProperty::qobjectBindableManualNotify()
QCOMPARE(object.foo(), 1);
}
+void tst_QProperty::qobjectBindableSignalTakingNewValue()
+{
+ // Given an object of type MyQObject,
+ MyQObject object;
+ // and tracking the values emitted via its fooChanged signal,
+ int newValue = -1;
+ QObject::connect(&object, &MyQObject::fooChanged, [&](int i){ newValue = i; } );
+
+ // when we change the property's value via the bindable interface
+ object.bindableFoo().setValue(1);
+ // we obtain the newly set value.
+ QCOMPARE(newValue, 1);
+
+ // The same holds true when we set a binding
+ QProperty<int> i {2};
+ object.bindableFoo().setBinding(Qt::makePropertyBinding(i));
+ QCOMPARE(newValue, 2);
+ // and when the binding gets reevaluated to a new value
+ i = 3;
+ QCOMPARE(newValue, 3);
+}
+
void tst_QProperty::testNewStuff()
{
MyQObject testReadOnly;