blob: fb90c32ab632ce586b86a43b8cf4e091bfd49e8d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// 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
*/
|