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 | |
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')
-rw-r--r-- | src/qmlmodels/doc/snippets/qml/listmodel/WorkerScript.qml | 43 | ||||
-rw-r--r-- | src/qmlmodels/doc/snippets/qml/listmodel/dataloader.mjs | 13 | ||||
-rw-r--r-- | src/qmlmodels/qqmllistmodel.cpp | 8 | ||||
-rw-r--r-- | src/qmlworkerscript/qquickworkerscript.cpp | 3 | ||||
-rw-r--r-- | src/quick/doc/qtquick.qdocconf | 3 | ||||
-rw-r--r-- | src/quick/doc/src/examples.qdoc | 1 |
6 files changed, 61 insertions, 10 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] + diff --git a/src/qmlmodels/qqmllistmodel.cpp b/src/qmlmodels/qqmllistmodel.cpp index 3bd180d072..e75fe22ebc 100644 --- a/src/qmlmodels/qqmllistmodel.cpp +++ b/src/qmlmodels/qqmllistmodel.cpp @@ -1981,7 +1981,7 @@ void DynamicRoleModelNodeMetaObject::propertyWritten(int index) \section1 Using Threaded List Models with WorkerScript - ListModel can be used together with WorkerScript access a list model + ListModel can be used together with WorkerScript to access a list model from multiple threads. This is useful if list modifications are synchronous and take some time: the list operations can be moved to a different thread to avoid blocking of the main GUI thread. @@ -1989,11 +1989,11 @@ void DynamicRoleModelNodeMetaObject::propertyWritten(int index) Here is an example that uses WorkerScript to periodically append the current time to a list model: - \snippet ../../examples/quick/threading/threadedlistmodel/timedisplay.qml 0 + \snippet qml/listmodel/WorkerScript.qml 0 The included file, \tt dataloader.mjs, looks like this: - \snippet ../../examples/quick/threading/threadedlistmodel/dataloader.mjs 0 + \snippet qml/listmodel/dataloader.mjs 0 The timer in the main example sends messages to the worker script by calling \l WorkerScript::sendMessage(). When this message is received, @@ -2004,7 +2004,7 @@ void DynamicRoleModelNodeMetaObject::propertyWritten(int index) You must call sync() or else the changes made to the list from that thread will not be reflected in the list model in the main thread. - \sa {qml-data-models}{Data Models}, {Qt Quick Examples - Threading}, {Qt QML} + \sa {qml-data-models}{Data Models}, {Qt QML} */ QQmlListModel::QQmlListModel(QObject *parent) diff --git a/src/qmlworkerscript/qquickworkerscript.cpp b/src/qmlworkerscript/qquickworkerscript.cpp index 8df631c6d3..f57d39b0c7 100644 --- a/src/qmlworkerscript/qquickworkerscript.cpp +++ b/src/qmlworkerscript/qquickworkerscript.cpp @@ -508,9 +508,6 @@ void QQuickWorkerScriptEngine::run() Worker scripts that are plain JavaScript sources can not use \l {qtqml-javascript-imports.html}{.import} syntax. Scripts that are ECMAScript modules can freely use import and export statements. - - \sa {Qt Quick Examples - Threading}, - {Threaded ListModel Example} */ QQuickWorkerScript::QQuickWorkerScript(QObject *parent) : QObject(parent), m_engine(nullptr), m_scriptId(-1), m_componentComplete(true) diff --git a/src/quick/doc/qtquick.qdocconf b/src/quick/doc/qtquick.qdocconf index 122ee83045..1dbf568d2f 100644 --- a/src/quick/doc/qtquick.qdocconf +++ b/src/quick/doc/qtquick.qdocconf @@ -92,8 +92,7 @@ imagedirs += images excludefiles += ../util/qquickpropertychanges_p.h examples.fileextensions += "*.qm" -manifestmeta.thumbnail.names += "QtQuick/Threaded ListModel Example" \ - "QtQuick/QML Dynamic View Ordering Tutorial*" +manifestmeta.thumbnail.names += "QtQuick/QML Dynamic View Ordering Tutorial*" manifestmeta.highlighted.names = "QtQuick/Qt Quick Demo - Same Game" diff --git a/src/quick/doc/src/examples.qdoc b/src/quick/doc/src/examples.qdoc index 738fe6a3dc..165084e79c 100644 --- a/src/quick/doc/src/examples.qdoc +++ b/src/quick/doc/src/examples.qdoc @@ -138,7 +138,6 @@ Creator. \div {class="doc-column"} \b{System and Events} \list - \li \l{Qt Quick Examples - Threading}{Threading} \li \l{Qt Quick Examples - Accessibility}{Accessibility} \li \l{Qt Quick Examples - externaldraganddrop}{External Drag and Drop} \li \l{Qt Quick Examples - Drag and Drop}{Drag and Drop} |