aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2023-06-23 16:11:31 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-09-08 20:30:52 +0000
commit0cea930c829e59362515e1c800ae8daaa6271df4 (patch)
treedd2d0e667a02ac8f4ec0be56b29a064ce30ae544 /src
parent3267be5b058b18cc499a92ee394949a6885ec109 (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' Change-Id: Iee8898e61adcf69dc67157a1eff5f6ac019a39ca Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 38373b81f37ccbf6ec66f43a70fe9622bbcc9593) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/qmlmodels/doc/snippets/qml/listmodel/WorkerScript.qml43
-rw-r--r--src/qmlmodels/doc/snippets/qml/listmodel/dataloader.mjs13
-rw-r--r--src/qmlmodels/qqmllistmodel.cpp8
-rw-r--r--src/qmlworkerscript/qquickworkerscript.cpp3
-rw-r--r--src/quick/doc/qtquick.qdocconf3
-rw-r--r--src/quick/doc/src/examples.qdoc1
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 78c0bb239e..3f44f1b10d 100644
--- a/src/quick/doc/qtquick.qdocconf
+++ b/src/quick/doc/qtquick.qdocconf
@@ -93,8 +93,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 ad09aa48b8..ffdc43aa0a 100644
--- a/src/quick/doc/src/examples.qdoc
+++ b/src/quick/doc/src/examples.qdoc
@@ -136,7 +136,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 - Drag and Drop}{Drag and Drop}
\li \l{Qt Quick Examples - Item Variable Refresh Rate}{Item Variable Refresh Rate}