Ok, this would work for now but if you find a better method please share :)
this is my WorkerScript JS file "dbprocessor.js"
@
var init = function(ids, overview) { // QML is ready
var db = openDatabaseSync("QDeclarativeExampleDB", "1.0", "The Example QML SQL!", 1000000);
db.transaction(
function(tx) {
// Create the database if it doesn't already exist
tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
// Add (another) greeting row
tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ ids, overview ]);
}
)
}
WorkerScript.onMessage = function(message) {
// ... long-running operations and calculations are done here
switch(message.msg)
{
case"init":
WorkerScript.sendMessage({ 'reply': 'Done init'});
init(message.ids, message.overview);
break;
}
@
And my main.qml file
@import Qt 4.7
Rectangle {
property bool done: false
id: top
width: 400
height: 400
property XmlListModel list: XmlListModel { id: xmlModel
source: "http://www.example.com/data.xml"
query: "/feed/xml/"
XmlRole { name: "ids"; query: "id/string()" }
XmlRole { name: "overview"; query: "description/string()" }
}
WorkerScript {
id: werk
source: "dbprocessor.js"
onMessage: console.log(messageObject.reply)
}
Component {
id: delegate
Text { // or whatever item
MouseArea { // Item click handler
anchors.fill: parent
onClicked: {
console.log("clicked");
} // implement the click handler in the JavaScript
}
//Just to view data inserted
text: ids
Component.onCompleted:{
if(!done)
{
for(var i=0; i< xmlModel.count; i++)
werk.sendMessage({'msg': "init", 'ids': xmlModel.get(i).ids, 'overview': xmlModel.get(i).overview });
done = true;
}
}
}
}
ListView {
anchors.fill: parent
model: top.list;
delegate: delegate;
}
}
@