diff options
author | Oliver Eftevaag <[email protected]> | 2023-06-23 16:11:31 +0200 |
---|---|---|
committer | Oliver Eftevaag <[email protected]> | 2023-07-04 00:18:47 +0200 |
commit | 38373b81f37ccbf6ec66f43a70fe9622bbcc9593 (patch) | |
tree | b66eeb48b0a982cb3fd19e18ca8468dec6c1700f /tests/manual/threading/threadedlistmodel | |
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 <[email protected]>
Diffstat (limited to 'tests/manual/threading/threadedlistmodel')
6 files changed, 117 insertions, 0 deletions
diff --git a/tests/manual/threading/threadedlistmodel/CMakeLists.txt b/tests/manual/threading/threadedlistmodel/CMakeLists.txt new file mode 100644 index 0000000000..68fb5c511c --- /dev/null +++ b/tests/manual/threading/threadedlistmodel/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(threadedlistmodel LANGUAGES C CXX ASM) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_manual_test(tst_manual_threadedlistmodel + GUI + SOURCES + threadedlistmodel.cpp + DEFINES + QT_DEPRECATED_WARNINGS + LIBRARIES + Qt::Gui + Qt::Qml + Qt::Quick +) + +# Resources: +set(qmake_immediate_resource_files + timedisplay.qml + dataloader.mjs +) + +qt_internal_add_resource(tst_manual_threadedlistmodel "qmake_immediate" + PREFIX + "/qt/qml/threadedlistmodel" + FILES + ${qmake_immediate_resource_files} +) diff --git a/tests/manual/threading/threadedlistmodel/dataloader.mjs b/tests/manual/threading/threadedlistmodel/dataloader.mjs new file mode 100644 index 0000000000..f94e1bf895 --- /dev/null +++ b/tests/manual/threading/threadedlistmodel/dataloader.mjs @@ -0,0 +1,12 @@ +// 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/tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp b/tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp new file mode 100644 index 0000000000..607e5eecb7 --- /dev/null +++ b/tests/manual/threading/threadedlistmodel/threadedlistmodel.cpp @@ -0,0 +1,19 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +#include <QtGui/qguiapplication.h> +#include <QtQuick/QQuickView> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QCoreApplication::setApplicationName("threadedlistmodel-manual-test"); + QCoreApplication::setOrganizationName("QtProject"); + + QQuickView view; + view.setSource(QUrl(QStringLiteral("qrc:/qt/qml/threadedlistmodel/timedisplay.qml"))); + view.show(); + + return app.exec(); +} diff --git a/tests/manual/threading/threadedlistmodel/threadedlistmodel.pro b/tests/manual/threading/threadedlistmodel/threadedlistmodel.pro new file mode 100644 index 0000000000..b3849b3e1a --- /dev/null +++ b/tests/manual/threading/threadedlistmodel/threadedlistmodel.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = threadedlistmodel +QT += qml quick + +SOURCES += threadedlistmodel.cpp +RESOURCES += threadedlistmodel.qrc diff --git a/tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc b/tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc new file mode 100644 index 0000000000..dbc5bc312d --- /dev/null +++ b/tests/manual/threading/threadedlistmodel/threadedlistmodel.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/qt/qml/threadedlistmodel"> + <file>timedisplay.qml</file> + </qresource> +</RCC> diff --git a/tests/manual/threading/threadedlistmodel/timedisplay.qml b/tests/manual/threading/threadedlistmodel/timedisplay.qml new file mode 100644 index 0000000000..9c14fb1d11 --- /dev/null +++ b/tests/manual/threading/threadedlistmodel/timedisplay.qml @@ -0,0 +1,42 @@ +// 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] + } +} |