08-20-2012 12:03 PM
I would like to get more information on the correct way to do this with Cascades. I am looking for a way to basically have:
TextField {
text: user.weight
}
Button {
text: "Plus 1"
onClicked: {
user.setWeight(user.weight + 1);
}
}
And the textfield automatically display the new value. I understand it is simple by writing in a textfield id and doing id.text = user.weight; but I am going to have dynamically changing listviews and several other textfields and if I could avoid having to write "rebinding" methods for all of them that would be awesome. But if this feature is not yet implemented in Cascades then I will go with writing the rebinding for now. Just wanted to make sure before I started that thats the only option.
08-20-2012 12:30 PM
See sample cascadescookbookqml, Slider.
Stuart
08-20-2012 01:29 PM
Right that, I can do but the issue comes with when I have backend C++ changes, such as
QML:
TextField {
text: user.weight
}
C++:
qml->setContextProperty("user", userObject);
qml->setContextProperty("appContext", this);
if I have
QML:
Button {
onClicked: {
appContext.increaseWeight();
}
}
C++:
public MyApp::increaseWeight() {
user.setWeight(user.weight + 1);
}
The weight value increases in the user object but is not reflected in the UI until I do something to set the text to the new value. Basically I am looking for an observer that will watch the bound variables for changes on the C++ side, and then update the UI when the change happens.
08-20-2012 02:08 PM
Excellent!
This is where signals and slots come into play.
The data model signals a change.
You want a controller that catches the change and updates its minions (the views).
That keeps the loose coupling between data model and UI that you want.
Stuart
08-24-2012 12:20 PM
Did you succeed?
Stuart
08-26-2012 10:06 AM