I'm learning QtQuick and I'm playing with data binding between C++ classes and QML properties.
In my C++ object Model, I have two properties :
Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
Q_PROPERTY(bool status READ getStatus WRITE setStatus NOTIFY statusChanged)
And in my .qml file :
TextEdit {
placeholderText: "Enter your name"
text: user.name
}
Checkbox {
checked: user.status
}
When I change the user name with setName
from my C++ code, it is automatically reflected in the view.
When I check/uncheck the checkbox, or when I call setStatus()
from my C++ code, nothing happens. It seems the property checked
of checkboxes haven't the same behavior as TextEdit
components.
I don't want to bind my properties in a declarative way. Doesn't Qt Quick support property binding ?
Thank you for your help.
checked
anduser.status
, it means that whenuser.status
changes, the checkbox will be (un)checked. If the user clicks on the checkbox, the binding gets removed. – leemessetStatus
, it should change the propertyuser.status
in QML and indeed trigger the checkbox as long as you didn't click on it before. And this only works if you emit thestatusChanged
signal withinsetStatus
. – leemessetStatus
method, but even to "user clicks on checkbox" scenario doesn't work. I will test tomorrow with another property name (maybe "enabled" is used for internal stuff in QML) and will retry with a minimal code. Thank you for your help. – Neozaru