![]() |
Qt 6.x
The Qt SDK
|
\macro Q_OBJECT_COMPAT_PROPERTY(containingClass, type, name, callback) More...
#include <qproperty.h>
Public Types | |
using | value_type = T |
using | parameter_type = T |
Public Member Functions | |
QObjectComputedProperty ()=default | |
parameter_type | value () const |
std::conditional_t< QTypeTraits::is_dereferenceable_v< T >, parameter_type, void > | operator-> () const |
parameter_type | operator* () const |
operator parameter_type () const | |
constexpr bool | hasBinding () const |
template<typename Functor > | |
QPropertyChangeHandler< Functor > | onValueChanged (Functor f) |
template<typename Functor > | |
QPropertyChangeHandler< Functor > | subscribe (Functor f) |
template<typename Functor > | |
QPropertyNotifier | addNotifier (Functor f) |
QtPrivate::QPropertyBindingData & | bindingData () const |
void | notify () |
Related Symbols | |
(Note that these are not member symbols.) | |
template< typename Class, typename T, auto offset, auto Callback > | QObjectBindableProperty () |
\macro Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback) | |
\macro Q_OBJECT_COMPAT_PROPERTY(containingClass, type, name, callback)
Declares a \l QObjectCompatProperty inside containingClass of type type with name name. The argument callback specifies a setter function to be called when the property is changed through the binding.
\macro Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(containingClass, type, name, callback, value)
Declares a \l QObjectCompatProperty inside of containingClass of type type with name name. The argument callback specifies a setter function to be called when the property is changed through the binding. value specifies an initialization value.
\inmodule QtCore
The QObjectComputedProperty class is a template class to help port old properties to the bindable property system.
QObjectComputedProperty is a read-only property which is recomputed on each read. It does not store the computed value. It is one of the Qt internal classes implementing \l {Qt Bindable Properties}. QObjectComputedProperty is usually not used directly, instead an instance of it is created by using the Q_OBJECT_COMPUTED_PROPERTY macro.
See the following example.
The rules for getters in \l {Bindable Property Getters and Setters} also apply for QObjectComputedProperty. Especially, the getter should be trivial and only return the value of the QObjectComputedProperty object. The callback given to the QObjectComputedProperty should usually be a private method which is only called by the QObjectComputedProperty.
No setter is required or allowed, as QObjectComputedProperty is read-only.
To correctly participate in dependency handling, QObjectComputedProperty has to know when its value, the result of the callback given to it, might have changed. Whenever a bindable property used in the callback changes, this happens automatically. If the result of the callback might change because of a change in a value which is not a bindable property, it is the developer's responsibility to call notify
on the QObjectComputedProperty object. This will inform dependent properties about the potential change.
Note that calling notify
might trigger change handlers in dependent properties, which might in turn use the object the QObjectComputedProperty is a member of. So notify
must not be called when in a transitional or invalid state.
QObjectComputedProperty is not suitable for use with a computation that depends on any input that might change without notice, such as the contents of a file.
Definition at line 1270 of file qproperty.h.
using QObjectComputedProperty< Class, T, Offset, Getter >::parameter_type = T |
Definition at line 1285 of file qproperty.h.
using QObjectComputedProperty< Class, T, Offset, Getter >::value_type = T |
Definition at line 1284 of file qproperty.h.
|
default |
|
inline |
Definition at line 1332 of file qproperty.h.
|
inline |
Definition at line 1338 of file qproperty.h.
References qGetBindingStorage(), and storage.
|
inlineconstexpr |
Definition at line 1314 of file qproperty.h.
|
inline |
Definition at line 1344 of file qproperty.h.
References qGetBindingStorage(), and storage.
|
inline |
Definition at line 1317 of file qproperty.h.
Referenced by QObjectComputedProperty< Class, T, Offset, Getter >::subscribe().
|
inline |
Definition at line 1309 of file qproperty.h.
References QObjectComputedProperty< Class, T, Offset, Getter >::value().
|
inline |
Definition at line 1304 of file qproperty.h.
References QObjectComputedProperty< Class, T, Offset, Getter >::value().
|
inline |
Definition at line 1296 of file qproperty.h.
References QObjectComputedProperty< Class, T, Offset, Getter >::value().
|
inline |
Definition at line 1324 of file qproperty.h.
References QObjectComputedProperty< Class, T, Offset, Getter >::onValueChanged().
|
inline |
Definition at line 1289 of file qproperty.h.
References qGetBindingStorage(), and QBindingStorage::registerDependency().
Referenced by QObjectComputedProperty< Class, T, Offset, Getter >::operator parameter_type(), QObjectComputedProperty< Class, T, Offset, Getter >::operator*(), and QObjectComputedProperty< Class, T, Offset, Getter >::operator->().
|
related |
\macro Q_OBJECT_COMPUTED_PROPERTY(containingClass, type, name, callback)
Declares a \l QObjectComputedProperty inside containingClass of type type with name name. The argument callback specifies a GETTER function to be called when the property is evaluated.
Constructs a property with a default constructed instance of T.