Threaded ListModel contains a ListView and a ListModel. The ListModel is updated asynchronusly in another thread, and the results propagate back to the main thread.
A timer requests updates from the worker thread periodically:
- \snippet examples/threading/threadedlistmodel/timedisplay.qml 0
+ \snippet quick/threading/threadedlistmodel/timedisplay.qml 0
Inside the worker thread, the ListModel is synchronized once the data is finished loading:
- \snippet examples/threading/threadedlistmodel/dataloader.js 0
+ \snippet quick/threading/threadedlistmodel/dataloader.js 0
WorkerScript contains an example of using a 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 examples/threading/workerscript/workerscript.qml 0
+ \snippet quick/threading/workerscript/workerscript.qml 0
The workerscript then is free to take a really long time to calculate it:
- \snippet examples/threading/workerscript/workerscript.js 0
+ \snippet quick/threading/workerscript/workerscript.js 0
When it's done, the result returns to the main scene via the WorkerScript element:
- \snippet examples/threading/workerscript/workerscript.qml 1
+ \snippet quick/threading/workerscript/workerscript.qml 1
*/
*/
/*!
-\fn iterator &QInplacelist::iterator::erase()
+\fn iterator &QIntrusiveList::iterator::erase()
Remove the current object from the list, and return an iterator to the next element.
*/
as a new QML element. It provides the current time through \c hour and \c minute
properties, like this:
- \snippet examples/qml/plugins/plugin.cpp 0
+ \snippet plugins/plugin.cpp 0
\dots
To make this class available as a QML type, create a plugin that registers
module will be named \c TimeExample (as defined in the project
file further below).
- \snippet examples/qml/plugins/plugin.cpp plugin
- \codeline
- \snippet examples/qml/plugins/plugin.cpp export
+ \snippet plugins/plugin.cpp plugin
This registers the \c TimeModel class with the 1.0 version of this
plugin library, as a QML type called \c Time. The Q_ASSERT statement
should be bundled with the plugin, so it needs to be specified in the \c qmldir
file:
- \quotefile examples/qml/plugins/imports/TimeExample/qmldir
+ \quotefile plugins/imports/TimeExample/qmldir
Once the project is built and installed, the new \c Time element can be
used by any QML component that imports the \c TimeExample module:
- \snippet examples/qml/plugins/plugins.qml 0
+ \snippet plugins/plugins.qml 0
The full source code is available in the \l {qml/plugins}{plugins example}.