diff options
| author | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2023-06-23 16:11:31 +0200 |
|---|---|---|
| committer | Oliver Eftevaag <oliver.eftevaag@qt.io> | 2023-07-04 00:18:47 +0200 |
| commit | 38373b81f37ccbf6ec66f43a70fe9622bbcc9593 (patch) | |
| tree | b66eeb48b0a982cb3fd19e18ca8468dec6c1700f /src/qmlmodels/doc/snippets/qml | |
| parent | add2620e2e710bd2f594973f22f048314d7060d8 (diff) | |
convert threading example to manual tests
The threading example used a LauncherList to combine
two different but related examples into one.
I've now separated both into a shared directory called
'threading'
Pick-to: 6.6
Change-Id: Iee8898e61adcf69dc67157a1eff5f6ac019a39ca
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/qmlmodels/doc/snippets/qml')
| -rw-r--r-- | src/qmlmodels/doc/snippets/qml/listmodel/WorkerScript.qml | 43 | ||||
| -rw-r--r-- | src/qmlmodels/doc/snippets/qml/listmodel/dataloader.mjs | 13 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/qmlmodels/doc/snippets/qml/listmodel/WorkerScript.qml b/src/qmlmodels/doc/snippets/qml/listmodel/WorkerScript.qml new file mode 100644 index 0000000000..4799878375 --- /dev/null +++ b/src/qmlmodels/doc/snippets/qml/listmodel/WorkerScript.qml @@ -0,0 +1,43 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick + +Rectangle { + color: "white" + width: 200 + height: 300 + + ListView { + anchors.fill: parent + model: listModel + delegate: Component { + Text { + required property string time + text: time + } + } + + ListModel { id: listModel } + + WorkerScript { + id: worker + source: "dataloader.mjs" + } + +// ![0] + Timer { + id: timer + interval: 2000; repeat: true + running: true + triggeredOnStart: true + + onTriggered: { + var msg = {'action': 'appendCurrentTime', 'model': listModel}; + worker.sendMessage(msg); + } + } +// ![0] + } +} + diff --git a/src/qmlmodels/doc/snippets/qml/listmodel/dataloader.mjs b/src/qmlmodels/doc/snippets/qml/listmodel/dataloader.mjs new file mode 100644 index 0000000000..eed1bca6f1 --- /dev/null +++ b/src/qmlmodels/doc/snippets/qml/listmodel/dataloader.mjs @@ -0,0 +1,13 @@ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +// ![0] +WorkerScript.onMessage = function(msg) { + if (msg.action == 'appendCurrentTime') { + var data = {'time': new Date().toTimeString()}; + msg.model.append(data); + msg.model.sync(); // updates the changes to the list + } +} +// ![0] + |
