summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-04-13 15:05:42 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2021-04-14 09:24:33 +0200
commitd5b79e876e38e03d105300d461af168894456acd (patch)
treeca80e2a1b00e734c08be532b2215c342ad15aae1 /tests/auto
parent865f3c2a11a7e7e1dedbb216669cdc2e091f45db (diff)
QBindable: Mark non-modifying methods as const
A few methods in QBindable which do not modify anything were not marked as const so far. This adds the missing const, and a test to verify that they work. As all methods are fully inline, this does not cause any binary compatibility issues. Fixes: QTBUG-89508 Change-Id: If06d33bc405232887b8c371c268840ba34dbadf6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
index 7ba5ba33b7..848226713c 100644
--- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
+++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp
@@ -80,6 +80,7 @@ private slots:
void typeNoOperatorEqual();
void bindingValueReplacement();
void quntypedBindableApi();
+ void readonlyConstQBindable();
void testNewStuff();
void qobjectObservers();
@@ -1030,6 +1031,26 @@ void tst_QProperty::quntypedBindableApi()
QVERIFY(propLess.takeBinding().isNull());
}
+void tst_QProperty::readonlyConstQBindable()
+{
+ QProperty<int> i {42};
+ const QBindable<int> bindableI(const_cast<const QProperty<int> *>(&i));
+
+ // check that read-only operations work with a const QBindable
+ QVERIFY(bindableI.isReadOnly());
+ QVERIFY(!bindableI.hasBinding());
+ // we can still create a binding to a read only bindable through the interface
+ QProperty<int> j;
+ j.setBinding(bindableI.makeBinding());
+ QCOMPARE(j.value(), bindableI.value());
+ int counter = 0;
+ auto observer = bindableI.subscribe([&](){++counter;});
+ QCOMPARE(counter, 1);
+ auto observer2 = bindableI.onValueChanged([&](){++counter;});
+ i = 0;
+ QCOMPARE(counter, 3);
+}
+
class MyQObject : public QObject
{
Q_OBJECT