Hi Gunther,
Thanks for looking into it. Could you suggest a work around to the following problem:
- In my main menu scene, I have a ListView with a ListModel that shows level meta data such as “performance score” , “unlocked”, “completed”
- The ListModel initialises with default values for all – but these values are updated with data from WebStorage
- After the user completes a level, GameScene updates the level meta data in WebStorage
- I needed the callback to refresh the ListModel above with the new WebStorage data
Here is a minimal example:
import Felgo 3.0
import QtQuick 2.0
GameWindow {
id: gameWindow
activeScene: scene
screenWidth: 960
screenHeight: 640
Scene {
id: scene
width: 480
height: 320
WebStorage {
id: storage
}
ListModel {
id: model
ListElement {name: "Level 1"; value: 50}
}
ListView {
anchors.centerIn: parent
model: model
delegate: Item {
width: parent.width
height: 50
Text {
anchors.centerIn: parent
text: value
}
}
}
function updateModel() {
for (var ii = 0; ii < model.count; ++ii)
{
var name = model.get(ii).name
var score = storage.getValue(name)
model.setProperty(ii, "value", score)
}
}
Component.onCompleted: updateModel() // update model with storage data as soon as possible
}
Component.onCompleted: {
// this actually takes place in my GameScene after a level finishes
// and I simulate this here
storage.setValue("Level 1", 50, scene.updateModel)
}
}
(it might not compile/run – I wrote this in a text editor as I don’t have QtCreator on hand)
As the callback mechanism doesn’t work, the model does not get updated. Is there a work around and hopefully better way to keep the ListModel and WebStorage in sync?