template<typename
Class, typename T, auto Offset, auto Setter, auto Signal = nullptr, auto Getter = nullptr>
class QObjectCompatProperty< Class, T, Offset, Setter, Signal, Getter >
\macro Q_OBJECT_BINDABLE_PROPERTY(containingClass, type, name, signal)
- Since
- 6.0
Declares a \l QObjectBindableProperty inside containingClass of type type with name name. If the optional argument signal is given, this signal will be emitted when the property is marked dirty.
- See also
- {Qt's Property System}, {Qt Bindable Properties}
\macro Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(containingClass, type, name, initialvalue, signal)
- Since
- 6.0
Declares a \l QObjectBindableProperty inside containingClass of type type with name name which is initialized to initialvalue. If the optional argument signal is given, this signal will be emitted when the property is marked dirty.
- See also
- {Qt's Property System}, {Qt Bindable Properties}
\inmodule QtCore
The QObjectCompatProperty class is a template class to help port old properties to the bindable property system.
- Since
- 6.0
QObjectCompatProperty is a generic container that holds an instance of T
and behaves mostly like QProperty, just like QObjectBindableProperty. It's one of the Qt internal classes implementing \l {Qt Bindable Properties}. Like QObjectBindableProperty, QObjectCompatProperty stores its management data structure in the surrounding QObject. The last template parameter specifies a method (of the owning class) to be called when the property is changed through the binding. This is usually a setter.
As explained in \l {Qt Bindable Properties}, getters and setters for bindable properties have to be almost trivial to be correct. However, in legacy code, there is often complex logic in the setter. QObjectCompatProperty is a helper to port these properties to the bindable property system.
With QObjectCompatProperty, the same rules as described in \l {Bindable Property Getters and Setters} hold for the getter. For the setter, the rules are different. It remains that every possible code path in the setter must write to the underlying QObjectCompatProperty, otherwise calling the setter might not remove a pre-existing binding, as it should. However, as QObjectCompatProperty will call the setter on every change, the setter is allowed to contain code like updating class internals or emitting signals. Every write to the QObjectCompatProperty has to be analyzed carefully to comply with the rules given in \l {Writing to a Bindable Property}.
Some of the pre-existing Qt classes (for example, \l QAbstractProxyModel) have properties with virtual setters. Special care must be taken when making such properties bindable.
For the binding to work properly, the property must be correctly handled in all reimplemented methods of each derived class.
Unless the derived class has access to the underlying property object, the base implementation must be called for the binding to work correctly.
If the derived class can directly access the property instance, there is no need to explicitly call the base implementation, but the property's value must be correctly updated.
Refer to \l {Bindable Properties with Virtual Setters and Getters} for more details.
In both cases the expected behavior must be documented in the property's documentation, so that users can correctly override the setter.
Properties for which these conditions cannot be met should not be made bindable.
- See also
- Q_OBJECT_COMPAT_PROPERTY, QObjectBindableProperty, {Qt's Property System}, {Qt Bindable Properties}
Definition at line 503 of file qproperty_p.h.