summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/declarative/workerlistmodel/dataloader.js14
-rw-r--r--examples/declarative/workerlistmodel/timedisplay.qml33
2 files changed, 47 insertions, 0 deletions
diff --git a/examples/declarative/workerlistmodel/dataloader.js b/examples/declarative/workerlistmodel/dataloader.js
new file mode 100644
index 0000000..eac7478
--- /dev/null
+++ b/examples/declarative/workerlistmodel/dataloader.js
@@ -0,0 +1,14 @@
+// ![0]
+WorkerScript.onMessage = function(msg) {
+ console.log("Worker told to", msg.action);
+
+ if (msg.action == 'appendCurrentTime') {
+ var data = {'time': new Date().toTimeString()};
+ msg.model.append(data);
+ msg.model.sync(); // updates the changes to the list
+
+ var msgToSend = {'msg': 'Model updated!'};
+ WorkerScript.sendMessage(msgToSend);
+ }
+}
+// ![0]
diff --git a/examples/declarative/workerlistmodel/timedisplay.qml b/examples/declarative/workerlistmodel/timedisplay.qml
new file mode 100644
index 0000000..3bf2630
--- /dev/null
+++ b/examples/declarative/workerlistmodel/timedisplay.qml
@@ -0,0 +1,33 @@
+// ![0]
+import Qt 4.6
+
+ListView {
+ width: 200
+ height: 300
+
+ model: listModel
+ delegate: Component {
+ Text { text: time }
+ }
+
+ WorkerListModel { id: listModel }
+
+ WorkerScript {
+ id: worker
+ source: "dataloader.js"
+ onMessage: {
+ console.log("Worker said", messageObject.msg);
+ }
+ }
+
+ Timer {
+ id: timer
+ interval: 2000; repeat: true; running: true; triggeredOnStart: true
+
+ onTriggered: {
+ var msg = {'action': 'appendCurrentTime', 'model': listModel};
+ worker.sendMessage(msg);
+ }
+ }
+}
+// ![0]