QBindable Class | Qt Core (original) (raw)
QBindable is a wrapper class around binding-enabled properties. It allows type-safe operations while abstracting the differences between the various property classes away. More...
Member Function Documentation
[explicit, since 6.5]
QBindable::QBindable(QObject *obj, const QMetaProperty &property)
See QBindable::QBindable(QObject *obj, const char *property)
This function was introduced in Qt 6.5.
[explicit, since 6.5]
QBindable::QBindable(QObject *obj, const char *property)
Constructs a QBindable for the Q_PROPERTY property on obj. The property must have a notify signal but does not need to have BINDABLE
in its Q_PROPERTY
definition, so even binding unaware Q_PROPERTY
s can be bound or used in binding expressions. You must use QBindable::value()
in binding expressions instead of the normal property READ
function (or MEMBER
) to enable dependency tracking if the property is not BINDABLE
. When binding using a lambda, you may prefer to capture the QBindable by value to avoid the cost of calling this constructor in the binding expression. This constructor should not be used to implement BINDABLE
for a Q_PROPERTY, as the resulting Q_PROPERTY will not support dependency tracking. To make a property that is usable directly without reading through a QBindable use QProperty or QObjectBindableProperty.
QProperty<QString> displayText; QDateTimeEdit *dateTimeEdit = findDateTimeEdit(); QBindable<QDateTime> dateTimeBindable(dateTimeEdit, "dateTime"); displayText.setBinding(dateTimeBindable{ return dateTimeBindable.value().toString(); });
This function was introduced in Qt 6.5.
See also QProperty, QObjectBindableProperty, and Qt Bindable Properties.
QPropertyBinding<T> QBindable::binding() const
Returns the currently set binding of the underlying property. If the property does not have a binding, the returned QPropertyBinding<T>
will be invalid.
See also setBinding and hasBinding.
QPropertyBinding<T> QBindable::makeBinding(const QPropertyBindingSourceLocation &location = QT_PROPERTY_DEFAULT_BINDING_LOCATION) const
Constructs a binding evaluating to the underlying property's value, using a specified source location.
QPropertyBinding<T> QBindable::setBinding(const QPropertyBinding<T> &binding)
Sets the underlying property's binding to binding. Does nothing if the QBindable is read-only or invalid.
See also binding, isReadOnly(), and isValid().
template QPropertyBinding<T> QBindable::setBinding(Functor f)
This is an overloaded function.
Creates a QPropertyBinding<T>
from f, and sets it as the underlying property's binding.
void QBindable::setValue(const T &value)
Sets the underlying property's value to value. This removes any currenltly set binding from it. This function has no effect if the QBindable is read-only or invalid.
See also value(), isValid(), isReadOnly(), and setBinding().
QPropertyBinding<T> QBindable::takeBinding()
Removes the currently set binding of the underlying property and returns it. If the property does not have a binding, the returned QPropertyBinding<T>
will be invalid.
See also binding, setBinding, and hasBinding.
T QBindable::value() const
Returns the underlying property's current value. If the QBindable is invalid, a default constructed T
is returned.