diff options
Diffstat (limited to 'examples/quick/threading')
16 files changed, 0 insertions, 400 deletions
diff --git a/examples/quick/threading/CMakeLists.txt b/examples/quick/threading/CMakeLists.txt deleted file mode 100644 index 0eb73afc76..0000000000 --- a/examples/quick/threading/CMakeLists.txt +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(threading LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/threading") - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick) - -qt_standard_project_setup() - -add_subdirectory("../shared" "shared") - -qt_add_executable(threadingexample - WIN32 - MACOSX_BUNDLE - main.cpp -) - -target_link_libraries(threadingexample PRIVATE - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -add_dependencies(threadingexample threading_shared) - -qt_add_qml_module(threadingexample - URI threading - AUTO_RESOURCE_PREFIX - QML_FILES - "threadedlistmodel/dataloader.mjs" - "threadedlistmodel/timedisplay.qml" - "threading.qml" - "workerscript/Spinner.qml" - "workerscript/workerscript.mjs" - "workerscript/workerscript.qml" -) - -install(TARGETS threadingexample - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) - -bundle_shared(threadingexample) diff --git a/examples/quick/threading/doc/images/qml-threading-example.png b/examples/quick/threading/doc/images/qml-threading-example.png Binary files differdeleted file mode 100644 index 6ed79ab190..0000000000 --- a/examples/quick/threading/doc/images/qml-threading-example.png +++ /dev/null diff --git a/examples/quick/threading/doc/src/threading.qdoc b/examples/quick/threading/doc/src/threading.qdoc deleted file mode 100644 index fb90c32ab6..0000000000 --- a/examples/quick/threading/doc/src/threading.qdoc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only -/*! - \title Qt Quick Examples - Threading - \example threading - \brief This is a collection of QML multithreading examples. - \image qml-threading-example.png - \ingroup qtquickexamples - - \e Threading is a collection of QML multithreading examples. - - \include examples-run.qdocinc - - \section1 Threaded ListModel - - \e{Threaded ListModel} contains a \l ListView and a \l ListModel. - The ListModel object is updated asynchronously in another thread, and the - results propagate back to the main thread. A timer requests updates from the - worker thread periodically: - \snippet threading/threadedlistmodel/timedisplay.qml 0 - - Inside the worker thread, the ListModel is synchronized once the data is - finished loading: - \snippet threading/threadedlistmodel/dataloader.mjs 0 - - \section1 WorkerScript - - \e WorkerScript contains an example of using a \l WorkerScript to offload - expensive calculations into another thread. This keeps the UI from being - blocked. This example calculates numbers in Pascal's Triangle, and not in a - very optimal way, so it will often take several seconds to complete the - calculation. By doing this in a WorkerScript in another thread, the UI is - not blocked during this time. - - When the UI needs another value, a request is sent to the WorkerScript: - \snippet threading/workerscript/workerscript.qml 0 - - The workerscript then is free to take a really long time to calculate it: - \snippet threading/workerscript/workerscript.mjs 0 - - When it's done, the result returns to the main scene via the WorkerScript - type: - \snippet threading/workerscript/workerscript.qml 1 -*/ diff --git a/examples/quick/threading/main.cpp b/examples/quick/threading/main.cpp deleted file mode 100644 index f9df4b795a..0000000000 --- a/examples/quick/threading/main.cpp +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -#include "../shared/shared.h" -DECLARATIVE_EXAMPLE_MAIN(threading/threading) diff --git a/examples/quick/threading/threadedlistmodel/dataloader.mjs b/examples/quick/threading/threadedlistmodel/dataloader.mjs deleted file mode 100644 index f94e1bf895..0000000000 --- a/examples/quick/threading/threadedlistmodel/dataloader.mjs +++ /dev/null @@ -1,12 +0,0 @@ -// 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/examples/quick/threading/threadedlistmodel/doc/src/threadedlistmodel.qdoc b/examples/quick/threading/threadedlistmodel/doc/src/threadedlistmodel.qdoc deleted file mode 100644 index 1f4d7b38e2..0000000000 --- a/examples/quick/threading/threadedlistmodel/doc/src/threadedlistmodel.qdoc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \title Threaded ListModel Example - \example threading/threadedlistmodel - \brief The Threaded ListModel example shows how to use a ListModel from multiple - threads using WorkerScript. - - This example shows how to use a ListModel from multiple threads using - WorkerScript. -*/ - diff --git a/examples/quick/threading/threadedlistmodel/threadedlistmodel.qmlproject b/examples/quick/threading/threadedlistmodel/threadedlistmodel.qmlproject deleted file mode 100644 index bfc1c25bf9..0000000000 --- a/examples/quick/threading/threadedlistmodel/threadedlistmodel.qmlproject +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QmlProject 1.1 - -Project { - mainFile: "timedisplay.qml" - - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } -} diff --git a/examples/quick/threading/threadedlistmodel/timedisplay.qml b/examples/quick/threading/threadedlistmodel/timedisplay.qml deleted file mode 100644 index 9c14fb1d11..0000000000 --- a/examples/quick/threading/threadedlistmodel/timedisplay.qml +++ /dev/null @@ -1,42 +0,0 @@ -// 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/examples/quick/threading/threading.pro b/examples/quick/threading/threading.pro deleted file mode 100644 index cd9ed25e0c..0000000000 --- a/examples/quick/threading/threading.pro +++ /dev/null @@ -1,10 +0,0 @@ -TEMPLATE = app - -QT += quick qml -SOURCES += main.cpp -RESOURCES += \ - threading.qrc \ - ../shared/shared.qrc - -target.path = $$[QT_INSTALL_EXAMPLES]/quick/threading -INSTALLS += target diff --git a/examples/quick/threading/threading.qml b/examples/quick/threading/threading.qml deleted file mode 100644 index 55a61ee155..0000000000 --- a/examples/quick/threading/threading.qml +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick -import shared as Examples - -Item { - height: 480 - width: 320 - Examples.LauncherList { - id: ll - anchors.fill: parent - Component.onCompleted: { - addExample("Threaded ListModel", "Updates a ListModel in another thread", Qt.resolvedUrl("threadedlistmodel/timedisplay.qml")); - addExample("WorkerScript", "Performs calculations in another thread", Qt.resolvedUrl("workerscript/workerscript.qml")); - } - } -} diff --git a/examples/quick/threading/threading.qmlproject b/examples/quick/threading/threading.qmlproject deleted file mode 100644 index 877dcd7d63..0000000000 --- a/examples/quick/threading/threading.qmlproject +++ /dev/null @@ -1,17 +0,0 @@ -import QmlProject 1.1 - -Project { - mainFile: "threading.qml" - importPaths: ["../"] - - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } -} diff --git a/examples/quick/threading/threading.qrc b/examples/quick/threading/threading.qrc deleted file mode 100644 index e20d9a111e..0000000000 --- a/examples/quick/threading/threading.qrc +++ /dev/null @@ -1,10 +0,0 @@ -<RCC> - <qresource prefix="/qt/qml/threading"> - <file>threading.qml</file> - <file>threadedlistmodel/timedisplay.qml</file> - <file>threadedlistmodel/dataloader.mjs</file> - <file>workerscript/Spinner.qml</file> - <file>workerscript/workerscript.mjs</file> - <file>workerscript/workerscript.qml</file> - </qresource> -</RCC> diff --git a/examples/quick/threading/workerscript/Spinner.qml b/examples/quick/threading/workerscript/Spinner.qml deleted file mode 100644 index c21433961e..0000000000 --- a/examples/quick/threading/workerscript/Spinner.qml +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick - -Rectangle { - width: 64 - height: 64 - property alias value: list.currentIndex - property alias label: caption.text - - Text { - id: caption - text: "Spinner" - anchors.horizontalCenter: parent.horizontalCenter - } - - Rectangle { - anchors.top: caption.bottom - anchors.topMargin: 4 - anchors.horizontalCenter: parent.horizontalCenter - height: 48 - width: 32 - color: "black" - ListView { - id: list - anchors.fill: parent - highlightRangeMode: ListView.StrictlyEnforceRange - preferredHighlightBegin: height/3 - preferredHighlightEnd: height/3 - clip: true - model: 64 - delegate: Text { - required property int index - font.pixelSize: 18; - color: "white"; - text: index; - anchors.horizontalCenter: parent.horizontalCenter - } - } - Rectangle { - anchors.fill: parent - gradient: Gradient { - GradientStop { position: 0.0; color: "#FF000000" } - GradientStop { position: 0.2; color: "#00000000" } - GradientStop { position: 0.8; color: "#00000000" } - GradientStop { position: 1.0; color: "#FF000000" } - } - } - } -} diff --git a/examples/quick/threading/workerscript/workerscript.mjs b/examples/quick/threading/workerscript/workerscript.mjs deleted file mode 100644 index 560c304b47..0000000000 --- a/examples/quick/threading/workerscript/workerscript.mjs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//Will be initialized when WorkerScript{} is instantiated -var cache = new Array(64); -for (var i = 0; i < 64; i++) - cache[i] = new Array(64); - -function triangle(row, column) { - if (cache[row][column]) - return cache[row][column] - if (column < 0 || column > row) - return -1; - if (column == 0 || column == row) - return 1; - return triangle(row-1, column-1) + triangle(row-1, column); -} -//! [0] -WorkerScript.onMessage = function(message) { - //Calculate result (may take a while, using a naive algorithm) - var calculatedResult = triangle(message.row, message.column); - //Send result back to main thread - WorkerScript.sendMessage( { row: message.row, - column: message.column, - result: calculatedResult} ); -} -//! [0] diff --git a/examples/quick/threading/workerscript/workerscript.qml b/examples/quick/threading/workerscript/workerscript.qml deleted file mode 100644 index 3d01f90968..0000000000 --- a/examples/quick/threading/workerscript/workerscript.qml +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick - -Rectangle { - width: 320; height: 480 - -//! [1] - WorkerScript { - id: myWorker - source: "workerscript.mjs" - - onMessage: (messageObject) => { - if (messageObject.row == rowSpinner.value && messageObject.column == columnSpinner.value){ //Not an old result - if (messageObject.result == -1) - resultText.text = "Column must be <= Row"; - else - resultText.text = messageObject.result; - } - } - } -//! [1] - Row { - y: 24 - spacing: 24 - anchors.horizontalCenter: parent.horizontalCenter -//! [0] - Spinner { - id: rowSpinner - label: "Row" - onValueChanged: { - resultText.text = "Loading..."; - myWorker.sendMessage( { row: rowSpinner.value, column: columnSpinner.value } ); - } - } -//! [0] - - Spinner { - id: columnSpinner - label: "Column" - onValueChanged: { - resultText.text = "Loading..."; - myWorker.sendMessage( { row: rowSpinner.value, column: columnSpinner.value } ); - } - } - } - - Text { - id: resultText - y: 180 - width: parent.width - horizontalAlignment: Text.AlignHCenter - wrapMode: Text.WordWrap - font.pixelSize: 32 - } - - Text { - text: "Pascal's Triangle Calculator" - anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom; bottomMargin: 50 } - } -} diff --git a/examples/quick/threading/workerscript/workerscript.qmlproject b/examples/quick/threading/workerscript/workerscript.qmlproject deleted file mode 100644 index 2eb5b7fe9f..0000000000 --- a/examples/quick/threading/workerscript/workerscript.qmlproject +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QmlProject 1.1 - -Project { - mainFile: "workerscript.qml" - - /* Include .qml, .js, and image files from current directory and subdirectories */ - QmlFiles { - directory: "." - } - JavaScriptFiles { - directory: "." - } - ImageFiles { - directory: "." - } -} |