diff options
-rw-r--r-- | src/corelib/kernel/qproperty.cpp | 3 | ||||
-rw-r--r-- | src/corelib/kernel/qproperty.h | 14 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp | 8 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/corelib/kernel/qproperty.cpp b/src/corelib/kernel/qproperty.cpp index e9256c7b42..27e2de7c4f 100644 --- a/src/corelib/kernel/qproperty.cpp +++ b/src/corelib/kernel/qproperty.cpp @@ -952,6 +952,9 @@ QString QPropertyBindingError::description() const Q_OBJECT_BINDABLE_PROPERTY(MyClass, int, xProp, &MyClass::xChanged) }; \endcode + + If the property does not need a changed notification, you can leave out the "NOFITY xChanged" in the Q_PROPERTY macro as well as the last argument + of the Q_OBJECT_BINDABLE_PROPERTY macro. */ /*! diff --git a/src/corelib/kernel/qproperty.h b/src/corelib/kernel/qproperty.h index a533f424e8..b6653c0411 100644 --- a/src/corelib/kernel/qproperty.h +++ b/src/corelib/kernel/qproperty.h @@ -1013,13 +1013,23 @@ private: } }; -#define Q_OBJECT_BINDABLE_PROPERTY(Class, Type, name, ...) \ +#define Q_OBJECT_BINDABLE_PROPERTY3(Class, Type, name) \ static constexpr size_t _qt_property_##name##_offset() { \ QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \ return offsetof(Class, name); \ QT_WARNING_POP \ } \ - QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, __VA_ARGS__> name; + QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, nullptr> name; + +#define Q_OBJECT_BINDABLE_PROPERTY4(Class, Type, name, Signal) \ + static constexpr size_t _qt_property_##name##_offset() { \ + QT_WARNING_PUSH QT_WARNING_DISABLE_INVALID_OFFSETOF \ + return offsetof(Class, name); \ + QT_WARNING_POP \ + } \ + QObjectBindableProperty<Class, Type, Class::_qt_property_##name##_offset, Signal> name; + +#define Q_OBJECT_BINDABLE_PROPERTY(...) QT_OVERLOADED_MACRO(Q_OBJECT_BINDABLE_PROPERTY, __VA_ARGS__) template<typename Class, typename T, auto Offset, auto Getter> class QObjectComputedProperty : public QUntypedPropertyData diff --git a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp index 3cc7bd6f9c..5ae92e8981 100644 --- a/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp +++ b/tests/auto/corelib/kernel/qproperty/tst_qproperty.cpp @@ -999,20 +999,18 @@ class MyQObject : public QObject Q_OBJECT Q_PROPERTY(int foo READ foo WRITE setFoo BINDABLE bindableFoo NOTIFY fooChanged) Q_PROPERTY(int bar READ bar WRITE setBar BINDABLE bindableBar NOTIFY barChanged) - Q_PROPERTY(int read READ read NOTIFY readChanged) + Q_PROPERTY(int read READ read) Q_PROPERTY(int computed READ computed STORED false) Q_PROPERTY(int compat READ compat WRITE setCompat NOTIFY compatChanged) signals: void fooChanged(); void barChanged(); - void readChanged(); void compatChanged(); public slots: void fooHasChanged() { fooChangedCount++; } void barHasChanged() { barChangedCount++; } - void readHasChanged() { readChangedCount++; } void compatHasChanged() { compatChangedCount++; } public: @@ -1044,13 +1042,12 @@ public: public: int fooChangedCount = 0; int barChangedCount = 0; - int readChangedCount = 0; int compatChangedCount = 0; int setCompatCalled = 0; Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, fooData, &MyQObject::fooChanged); Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, barData, &MyQObject::barChanged); - Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, readData, &MyQObject::readChanged); + Q_OBJECT_BINDABLE_PROPERTY(MyQObject, int, readData); Q_OBJECT_COMPUTED_PROPERTY(MyQObject, int, computedData, &MyQObject::computed); Q_OBJECT_COMPAT_PROPERTY(MyQObject, int, compatData, &MyQObject::setCompat) }; @@ -1060,7 +1057,6 @@ void tst_QProperty::testNewStuff() MyQObject object; QObject::connect(&object, &MyQObject::fooChanged, &object, &MyQObject::fooHasChanged); QObject::connect(&object, &MyQObject::barChanged, &object, &MyQObject::barHasChanged); - QObject::connect(&object, &MyQObject::readChanged, &object, &MyQObject::readHasChanged); QCOMPARE(object.fooChangedCount, 0); object.setFoo(10); |