QUntypedBindable Class
QUntypedBindable 是可绑定属性(如任何类型的QProperty\<T\>
和QObjectBindableProperty
)的统一接口T
。更多
头文件: | #include <QUntypedBindable> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
自 | Qt 6.0 |
继承: |
公共函数
QUntypedBindable() | |
QUntypedBindable(Property *property) | |
QPropertyNotifier | addNotifier(Functor f) |
QUntypedPropertyBinding | binding() const |
bool | hasBinding() const |
(since 6.1) bool | isReadOnly() const |
bool | isValid() const |
QUntypedPropertyBinding | makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const |
(since 6.2) QMetaType | metaType() const |
QPropertyChangeHandler<Functor> | onValueChanged(Functor f) const |
bool | setBinding(const QUntypedPropertyBinding &binding) |
QPropertyChangeHandler<Functor> | subscribe(Functor f) const |
(since 6.1) QUntypedPropertyBinding | takeBinding() |
详细描述
QUntypedBindable 是一个完全类型化的通用接口,用于封装可绑定属性。您可以使用它与属性交互,而无需知道它们的类型,也无需关心它们是哪种可绑定属性(例如QProperty 或QObjectBindableProperty )。对于大多数用例,最好使用QBindable<T>(它是属性实现的通用接口,但有固定的类型)。
成员函数文档
[constexpr noexcept]
QUntypedBindable::QUntypedBindable()
Default-构造一个 QUntypedBindable。它处于无效状态。
另请参见 isValid().
template <typename Property> QUntypedBindable::QUntypedBindable(Property *property)
从属性property 构造一个 QUntypedBindable。如果属性为常量,QUntypedBindable 将是只读的。如果property 为空,QUntypedBindable 将无效。
另请参阅 isValid() 和isReadOnly() 。
template <typename Functor> QPropertyNotifier QUntypedBindable::addNotifier(Functor f)
安装f 作为变更处理程序。每当底层属性发生变化时,只要返回的QPropertyNotifier
和属性保持不变,f 就会被调用。
在某些情况下,该方法比onValueChanged() 更容易使用,因为返回的对象不是模板。因此,它更容易存储,例如作为类中的一个成员。
另请参阅 onValueChanged() 和subscribe()。
QUntypedPropertyBinding QUntypedBindable::binding() const
返回底层属性的绑定(如果有),否则返回默认构造的 QUntypedPropertyBinding。
另请参阅 setBinding() 和hasBinding()。
bool QUntypedBindable::hasBinding() const
如果底层属性有绑定,则返回true
。
[since 6.1]
bool QUntypedBindable::isReadOnly() const
如果QUntypedBindable 为只读,则返回 true。
此函数在 Qt 6.1 中引入。
bool QUntypedBindable::isValid() const
如果QUntypedBindable 有效,则返回 true。除非另有说明,否则在无效QUntypedBindable 上调用的方法一般不会产生任何效果。
QUntypedPropertyBinding QUntypedBindable::makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const
使用指定的源location 创建返回底层属性值的绑定。
[since 6.2]
QMetaType QUntypedBindable::metaType() const
返回据以创建QUntypedBindable 的属性的元类型。如果绑定无效,将返回无效的元类型。
此函数在 Qt 6.2 中引入。
另请参阅 isValid().
template <typename Functor> QPropertyChangeHandler<Functor> QUntypedBindable::onValueChanged(Functor f) const
安装f 作为变更处理程序。每当底层属性发生变化时,只要返回的QPropertyChangeHandler
和属性保持激活状态,f 就会被调用。每次值发生变化时,处理程序会根据上下文立即调用或延迟调用。
另请参阅 onValueChanged() 和subscribe()。
bool QUntypedBindable::setBinding(const QUntypedPropertyBinding &binding)
将底层属性的绑定设置为binding 。如果QUntypedBindable 为只读、空或binding 的类型与底层属性的类型一致,则不会有任何影响。
绑定设置成功后,将返回true
。
另请参阅 binding() 。
template <typename Functor> QPropertyChangeHandler<Functor> QUntypedBindable::subscribe(Functor f) const
行为类似于调用f ,然后再调用onValueChanged(f)
、
另请参见 onValueChanged().
[since 6.1]
QUntypedPropertyBinding QUntypedBindable::takeBinding()
从属性中删除并返回当前设置的绑定。如果未设置绑定,则返回默认构造的 QUntypedPropertyBinding。
此函数在 Qt 6.1 中引入。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.