diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index a085aac3d1..717c6713d4 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -577,7 +577,7 @@ public: bool isBindable() const { return iface && iface->getBinding; } bool isReadOnly() const { return !(iface && iface->setBinding && iface->setObserver); } - QUntypedPropertyBinding makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) + QUntypedPropertyBinding makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const { return iface ? iface->makeBinding(data, location) : QUntypedPropertyBinding(); } @@ -597,14 +597,14 @@ public: return binding; } - void observe(QPropertyObserver *observer) + void observe(QPropertyObserver *observer) const { if (iface) iface->setObserver(data, observer); } template - QPropertyChangeHandler onValueChanged(Functor f) + QPropertyChangeHandler onValueChanged(Functor f) const { QPropertyChangeHandler handler(f); observe(&handler); @@ -612,7 +612,7 @@ public: } template - QPropertyChangeHandler subscribe(Functor f) + QPropertyChangeHandler subscribe(Functor f) const { f(); return onValueChanged(f); @@ -658,7 +658,7 @@ public: } } - QPropertyBinding makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) + QPropertyBinding makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const { return static_cast &&>(QUntypedBindable::makeBinding(location)); } diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index b73c050e5b..13a870ac9e 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -12,7 +12,7 @@ endif() # Only include the following tools when performing a host build if(NOT CMAKE_CROSSCOMPILING) add_subdirectory(androiddeployqt) - if(QT_FEATURE_gui) + if(QT_FEATURE_gui AND QT_FEATURE_systemsemaphore) add_subdirectory(androidtestrunner) endif() endif() 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 i {42}; + const QBindable bindableI(const_cast *>(&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 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