QProperty 类是启用自动特性绑定的模板类。 更多...
头: | #include <QProperty> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Since: | Qt 6.0 |
继承: | QPropertyData |
QProperty () | |
QProperty (const QPropertyBinding<T> & binding ) | |
QProperty (Functor && f ) | |
QProperty (const T & initialValue ) | |
QProperty (T && initialValue ) | |
~QProperty () | |
QPropertyNotifier | addNotifier (Functor f ) |
QPropertyBinding<T> | binding () const |
QPropertyChangeHandler<Functor> | onValueChanged (Functor f ) |
QPropertyBinding<T> | setBinding (const QPropertyBinding<T> & newBinding ) |
bool | setBinding (const QUntypedPropertyBinding & newBinding ) |
QPropertyBinding<T> | setBinding (Functor f ) |
void | setValue (QProperty::rvalue_ref newValue ) |
void | setValue (QProperty::parameter_type newValue ) |
QPropertyChangeHandler<Functor> | subscribe (Functor f ) |
QPropertyBinding<T> | takeBinding () |
QProperty::parameter_type | value () const |
QProperty<T> & | operator= (QProperty::rvalue_ref newValue ) |
QProperty<T> & | operator= (QProperty::parameter_type newValue ) |
QProperty<T> & | operator= (const QPropertyBinding<T> & newBinding ) |
void | beginPropertyUpdateGroup () |
void | endPropertyUpdateGroup () |
QProperty<T> is one of the classes implementing Qt Bindable Properties . It is a container that holds an instance of T. You can assign a value to it and you can read it via the value () function or the T conversion operator. You can also tie the property to an expression that computes the value dynamically, the binding expression. It is represented as a C++ lambda and can be used to express relationships between different properties in your application.
注意: In the case of QML it is important that QProperty needs to be exposed in Q_PROPERTY with the BINDABLE keyword. As a result the QML engine, uses it as the bindable interface to set up the property binding. In turn, the binding can be then interacted with C++ via the normal API like:
QProperty<T>::onValueChanged, QProperty::takeBinding and QBindable::hasBinding
If the property is BINDABLE, then the engine will use the change-tracking inherent to the C++ property system for getting notified about changes; and won't rely on signals being emitted.
赋值 newValue to this property and removes the property's associated binding, if present.
赋值 newValue to this property and returns a reference to this QProperty .
Constructs a property with a default constructed instance of T.
[explicit]
QProperty::
QProperty
(const
QPropertyBinding
<
T
> &
binding
)
Constructs a property that is tied to the provided binding expression. The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly.
[explicit]
template <typename Functor> QProperty::
QProperty
(
Functor
&&
f
)
Constructs a property that is tied to the provided binding expression f . The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly.
[explicit default]
QProperty::
QProperty
(const
T
&
initialValue
)
Constructs a property with the provided initialValue .
[explicit default]
QProperty::
QProperty
(
T
&&
initialValue
)
Move-Constructs a property with the provided initialValue .
销毁特性。
Subscribes the given functor f as a callback that is called whenever the value of the property changes.
The callback
f
is expected to be a type that has a plain call operator
()
without any parameters. This means that you can provide a C++ lambda expression, a std::function or even a custom struct with a call operator.
The returned property change handler object keeps track of the subscription. When it goes out of scope, the callback is unsubscribed.
This method is in some cases easier to use than onValueChanged (), as the returned object is not a template. It can therefore more easily be stored, e.g. as a member in a class.
另请参阅 onValueChanged () 和 subscribe ().
Returns the binding expression that is associated with this property. A default constructed QPropertyBinding<T> will be returned if no such association exists.
另请参阅 setBinding ().
Registers the given functor f as a callback that shall be called whenever the value of the property changes. On each value change, the handler is either called immediately, or deferred, depending on the context.
The callback
f
is expected to be a type that has a plain call operator
()
without any parameters. This means that you can provide a C++ lambda expression, a std::function or even a custom struct with a call operator.
The returned property change handler object keeps track of the registration. When it goes out of scope, the callback is de-registered.
Associates the value of this property with the provided newBinding expression and returns the previously associated binding. The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly.
另请参阅 binding ().
这是重载函数。
Associates the value of this property with the provided newBinding expression. The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly.
Returns true if the type of this property is the same as the type the binding function returns; false otherwise.
这是重载函数。
Associates the value of this property with the provided functor f and returns the previously associated binding. The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated, and the property's value gets updated accordingly.
另请参阅 Formulating a Property Binding .
Subscribes the given functor f as a callback that is called immediately and whenever the value of the property changes in the future. On each value change, the handler is either called immediately, or deferred, depending on the context.
The callback f is expected to be a type that can be copied and has a plain call operator() without any parameters. This means that you can provide a C++ lambda expression, a std::function or even a custom struct with a call operator.
The returned property change handler object keeps track of the subscription. When it goes out of scope, the callback is unsubscribed.
Disassociates the binding expression from this property and returns it. After calling this function, the value of the property will only change if you assign a new value to it, or when a new binding is set.
Returns the value of the property. This may evaluate a binding expression that is tied to this property, before returning the value.
另请参阅 setValue ().
[default]
QProperty
<
T
> &QProperty::
operator=
(const
QPropertyBinding
<
T
> &
newBinding
)
Associates the value of this property with the provided newBinding expression and returns a reference to this property. The property's value is set to the result of evaluating the new binding. Whenever a dependency of the binding changes, the binding will be re-evaluated.
[since 6.2]
void
beginPropertyUpdateGroup
()
标记特性更新组的开始。在此组中,改变特性既不会立即更新任何从属特性,也不会触发变化通知。代之这些将延迟,直到结束组通过调用 endPropertyUpdateGroup .
组可以嵌套。在此情况下,延迟才结束,在最外层组已结束后。
注意: 改变通知才发送,在受组影响的所有特性值都已更新到其新值后。这允许重新建立类不变体若需要更新多个特性,以阻止任何外部观测器预告不一致状态。
该函数在 Qt 6.2 引入。
另请参阅 Qt::endPropertyUpdateGroup .
[since 6.2]
void
endPropertyUpdateGroup
()
Ends a property update group. If the outermost group has been ended, and deferred binding evaluations and notifications happen now.
警告: 调用 endPropertyUpdateGroup 之前不调用 beginPropertyUpdateGroup 产生未定义行为。
该函数在 Qt 6.2 引入。
另请参阅 Qt::beginPropertyUpdateGroup .