[SailfishDevel] Wrap data in Item to get notifiable properties ?

sfietkonstantin at free.fr sfietkonstantin at free.fr
Tue Dec 2 09:40:38 UTC 2014

Hi François,

The best way to do this is to use QML ListModel. Instead of loading the properties in a JS object, you can load them as model properties (via http://qt-project.org/doc/qt-5/qml-qtqml-models-listmodel.html#set-method). Accessing the properties would be done via "model":

DetailItem {
    label: qsTr("MyProp")
    value: model.myProp

If you don't want to use a ListModel, prefer using QtObject instead of Item. QtObject provides a non-graphical component to store properties, unlike Item that implies having a "box" (x, y, width, height, anchors etc.)


----- Mail original -----
De: "François K." <daitheflu at free.fr>
À: "Sailfish OS Developers" <devel at lists.sailfishos.org>
Envoyé: Mardi 2 Décembre 2014 10:31:46
Objet: [SailfishDevel] Wrap data in Item to get notifiable properties ?


I'm writing a small app for SailfishOS in JS + QML (I don't know C++ so please don't tell me to do this in C++).

I'm getting data from LocalStorage and hence get a Javascript Object with its own properties. Let's call it myObj.
Then I bind some field in a view to these properties :

    DetailItem {
        label: qsTr("MyProp")
        value: myObj.myProp

Now, if I update myObj.myProp, the value of the DetailItem doesn't get updated.
For what I understand, this is normal because the properties of my Javascript Object (myObj) aren't notifiable and thus, QML doesn't know it has been updated.

To fix this, I wonder if it's OK to wrap my JS object into a QML Item. This would give me notifiables properties and would certainly allow me to get working bindings.

What do you think about this ? Is it OK ?

Thanks a lot for your help,

Best wishes,

SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscribe at lists.sailfishos.org

More information about the Devel mailing list