[Qt-qml] PROBLEM : "state" of object inside ListView does not update correctly

bea.lam at nokia.com bea.lam at nokia.com
Tue Feb 1 04:19:24 CET 2011


On 31/01/2011, at 10:20 AM, ext Francesco Nwokeka wrote:

> On Sunday 30 January 2011 18:19:25 jyrki.yli-nokari at nokia.com wrote:
>> Use the setProperty
>> http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html#setProperty-method
>> It's not an ordinary JavaScript object.
>> 
>> I.e.  Instead of
>> "tagColumnModel.get( pos ).tagState = "newState"; "
>> Do
>> "tagColumnModel.setProperty(pos, "tagState", "newState"); "
> 
> Tried that, but it was a bit buggy. I solved the issue by going 100% on a c++ model and checking the 
> "state" ( a Q_PROPERTY ) from  there.


Using get() and setProperty() should both work. However, some bugs were fixed in ListModel recently relating to setting properties via these methods, so it's possible that you were seeing these issues.

The following code works fine with the latest source:


ListView {
    width: 200; height: 200

    model: ListModel {
        id: tagColumnModel
        ListElement { tagName: "apple"; tagState: "" }
        ListElement { tagName: "pear"; tagState: "" }
    }

    delegate: Rectangle {
        id: rect
        width: 200; height: 80
        Text { text: tagName }
        state: tagState
        states: State {
            name: "blah"
            PropertyChanges { target: rect; color: "red" }
        }
    }

    Component.onCompleted: {
        tagColumnModel.get(0).tagState = "blah";
    }
}


regards,

Bea



More information about the Qt-qml mailing list