Hi
I’m sure this is a noob issue. I’m loading words into Storage (read/parsed from a data file), so I presume once I set a value there (using setValue) that it becomes persistent (i.e. next time, I run the data is available) but when I run the following test on my Windows PC, I never get persistent storage, i.e. I have to reload upon each build/run. Please let me know where i’ve gone wrong. Thanks. BTW I will persue the better ways in future, but this first step is just to help me along with some basic understandings.
import VPlay 1.0
import QtQuick 1.1
GameWindow {
activeScene: scene
width: 960; height: 640
property string loadStatus: "load failed"
Storage {
id: myLocalStorage
// databaseName: "words"
onStorageError: {
console.debug("myLocalStorage: there was an error:", errorData.message)
}
}
Component.onCompleted: {
var isFirstStartApplication = myLocalStorage.getValue("ZEBRA")
if (isFirstStartApplication == undefined) {
// if undefined is returned, load up database
var storageData = fileUtils.readFile("files/dictionary.txt")
if (storageData) {
loadStatus = "loaded OK!"
var arr = storageData.split(",");
console.debug("words read = " + arr.length)
loadStatus = "words read = " + arr.length
// parse cvs file to populate storage
var obj = {};
for (var i = 0; i < arr.length - 1; i += 1) {
myLocalStorage.setValue(arr[i + 1], true)
}
} else {
loadStatus = "loaded failure!"
console.debug("loaded file FAILED")
}
}
}
Scene {
id: scene
width: 480; height: 320
Text { // notification
id: status
text: loadStatus
anchors.centerIn: parent
color: "white"
}
Rectangle {
id: rectangle
color: "grey"
width: 100; height: 50
Text {
id: textElement
text: qsTr("Lookup word")
color: "#ffffff"
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onPressed: {
if (myLocalStorage.getValue("ZEBRA")) {
status.text = "word found!"
}
else {
status.text = "word NOT found!"
}
}
}
}
}
}