Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Developer
HuXu77
Posts: 191
Registered: ‎02-10-2011
My Carrier: Verizon

Data Binding

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.

 

 

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: Data Binding

See sample cascadescookbookqml, Slider.

 

Stuart

Please use plain text.
Developer
HuXu77
Posts: 191
Registered: ‎02-10-2011
My Carrier: Verizon

Re: Data Binding

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.

_________________________________________________
Apps
Go Music
Flashlight Fast Free/Pro
Fitbit for BlackBerry PlayBook
Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: Data Binding

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

Please use plain text.
BlackBerry Development Advisor
smacmartin
Posts: 499
Registered: ‎05-07-2012
My Carrier: developer

Re: Data Binding

Did you succeed?

 

Stuart

Please use plain text.
Contributor
AlterX
Posts: 38
Registered: ‎08-21-2012
My Carrier: no

Re: Data Binding

Using signals you can resolve all of that!
Nokia Qt Ambassador
Please use plain text.