IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QProperty Class

The QProperty class is a template class that enables automatic property bindings.

This class was introduced in Qt 6.0.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QProperty Class

  • Header: QProperty

  • Since: Qt 6.0

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Inherits: QPropertyData

  • Group: QProperty is part of tools

Detailed Description

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.

Member Function Documentation

 

void QProperty::setValue(QProperty::parameter_type newValue)

void QProperty::setValue(QProperty::rvalue_ref newValue)

Assigns newValue to this property and removes the property's associated binding, if present.

QProperty<T> &QProperty::operator=(QProperty::parameter_type newValue)

QProperty<T> &QProperty::operator=(QProperty::rvalue_ref newValue)

Assigns newValue to this property and returns a reference to this QProperty.

QProperty::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 first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

[explicit] QProperty::QProperty(Functor &&f)

Constructs a property that is tied to the provided binding expression f. The first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

[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.

QProperty::~QProperty()

Destroys the property.

QPropertyBinding<T> QProperty::binding() const

Returns the binding expression that is associated with this property. A default constructed QPropertyBinding<T> will be returned if no such association exists.

See Also

See also setBinding()

QPropertyChangeHandler<Functor> QProperty::onValueChanged(Functor f)

Registers the given functor f as a callback that shall be 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, an 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.

QPropertyBinding<T> QProperty::setBinding(const QPropertyBinding<T> &newBinding)

Associates the value of this property with the provided newBinding expression and returns the previously associated binding. The first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

See Also

See also binding()

bool QProperty::setBinding(const QUntypedPropertyBinding &newBinding)

This is an overloaded function.

Associates the value of this property with the provided newBinding expression. The first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

Returns true if the type of this property is the same as the type the binding function returns; false otherwise.

QPropertyBinding<T> QProperty::setBinding(Functor f)

This is an overloaded function.

Associates the value of this property with the provided functor f and returns the previously associated binding. The first time the property value is read, the binding is evaluated by invoking the call operator () of f. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

QPropertyChangeHandler<Functor> QProperty::subscribe(Functor f)

Subscribes the given functor f as a callback that is called immediately and whenever the value of the property changes in the future.

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, an 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.

QPropertyBinding<T> QProperty::takeBinding()

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.

QProperty::parameter_type QProperty::value() const

Returns the value of the property. This may evaluate a binding expression that is tied to this property, before returning the value.

See Also

See also 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 first time the property value is read, the binding is evaluated. Whenever a dependency of the binding changes, the binding will be re-evaluated the next time the value of this property is read.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+