QUntypedBindable Class
QUntypedBindable 是一个统一接口,适用于任何类型T 的可绑定属性,例如QProperty\<T\> 和QObjectBindableProperty 。更多内容...
| 标题: | #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 default] QUntypedBindable::QUntypedBindable()
默认构造一个 QUntypedBindable。它处于无效状态。
另请参阅 isValid()。
template <typename Property> QUntypedBindable::QUntypedBindable(Property *property)
根据属性property 构建一个QUntypedBindable对象。如果Property是const,则该QUntypedBindable对象为只读。如果property 为null,则该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() 和QUntypedPropertyBinding::valueMetaType()。
template <typename Functor> QPropertyChangeHandler<Functor> QUntypedBindable::onValueChanged(Functor f) const
将f 注册为变更处理程序。只要返回的QPropertyChangeHandler 和该属性仍存在,每当底层属性发生变化时,都会调用f 。每次值发生变化时,处理程序会根据上下文立即调用或延迟调用。
另请参阅 QProperty::onValueChanged() 和subscribe()。
bool QUntypedBindable::setBinding(const QUntypedPropertyBinding &binding)
将底层属性的绑定设置为 `binding`。如果 `QUntypedBindable ` 为只读、为 `null`,或者 `binding` 的类型与底层属性的类型不匹配,则此操作不会产生任何效果。
当绑定成功设置时,返回true 。
另请参阅 binding() 和QUntypedPropertyBinding::valueMetaType()。
template <typename Functor> QPropertyChangeHandler<Functor> QUntypedBindable::subscribe(Functor f) const
其行为类似于先调用 `f `,然后调用 `onValueChanged(f)`,
另请参阅 onValueChanged()。
[since 6.1] QUntypedPropertyBinding QUntypedBindable::takeBinding()
从属性中移除当前设置的绑定,并返回该属性。如果未设置绑定,则返回一个通过默认构造函数构造的QUntypedPropertyBinding 。
该函数在 Qt 6.1 中引入。
© 2026 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.