[solved] How to change values of a ListModel from States when it's in another qml file?
-
Hi, I'm trying to change values in a ListModel from States. The starting point is http://doc.qt.nokia.com/4.7-snapshot/qml-listmodel.html#set-method
@fruitModel.set(3, {"cost": 5.95, "name":"Pizza"})@
However, what would be the syntax in the example above if the ListModel is in another qml file e.g. TheFruitModel.qml ?
And how can you set these changes from a State?
I'm attempting to do it following this syntax, but somehow it doesn't work:
@StateChangeScript { script: TheFruitModel.set(3, {"cost": 5.95, "name":"Pizza"}) }@
-
Where is your fruitModel declared? You can't access ids that are declared in another qml file (with exception of accessing ids that are declared in qml file which agregates current qml file).
-
Do you mean that I would need to 'import The FruitModel.qml'?
The "GridView documentation":http://doc.qt.nokia.com/4.7-snapshot/qml-gridview.html says:
bq. This model can be referenced as ContactModel in other QML files. See "QML Modules":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativemodules.html#qml-modules for more information about creating reusable components like this.
But a simple example for newbies would be nice since the QML Modules page touches many things and at least for me it's not evident to see what I'm supposed to do.
In the example of this thread fruitModel would be declared in TheFruitModel.qml, while
@fruitModel.set(3, {"cost": 5.95, "name":"Pizza"})@
would be in a different document, say MainPage.qml
fwiw the real example I'm facing is that I want to place the set() method at "OnlineBoard.qml":https://gitorious.org/testdef/testdef/blobs/master/testdef/qml/OnlineBoard.qml , where GridView and delegate are defined, while the ListModel itself is placed in "BoardModel.qml":https://gitorious.org/testdef/testdef/blobs/master/testdef/qml/BoardModel.qml
Thank you for your help!
-
So in your chessboardGrid you have model BoardModel {}.
You can use
@
chessboardGrid.model.set(/.../);
@