So I know how to bind QML property to C++ property, so when C++ one calls notify signal, QML updates the view. Is there any way to make C++ property update when user changes something using UI?
For example, I have a Combobox, and I want some C++ property to be updated when user changes value of combobox.
EDIT: By C++ properties I mean Q_PROPERTY
macro in QObject
-derived classes.
Property bindings are a core feature of QML that lets developers specify relationships between different object properties. When a property's dependencies change in value, the property is automatically updated according to the specified relationship.
A property is an attribute of an object that can be assigned a static value or bound to a dynamic expression. A property's value can be read by other objects. Generally it can also be modified by another object, unless a particular QML type has explicitly disallowed this for a specific property.
You should always use QObject::setProperty(), QQmlProperty or QMetaProperty::write() to change a QML property value, to ensure the QML engine is made aware of the property change.
To bind a property from an object you didn't create in QML (or was created in another context), you have to use Binding
.
In your case :
Binding {
target: yourCppObject
property: "cppPropertyName"
value: yourComboBox.currentText
}
Perhaps an answer to a similar question would be helpful.
It shows how to connect the standard (not custom) qml property with something in C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With