This file is indexed.

/usr/share/qt5/doc/qtquick/qtquick-threading-example.html is in qtdeclarative5-doc-html 5.2.1-3ubuntu15.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- threading.qdoc -->
  <title>Qt Quick Examples - Threading | QtQuick 5.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li>Qt 5.2</li>
<li><a href="qtquick-index.html">Qt Quick</a></li>
<li>Qt Quick Examples - Threading</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<h1 class="title">Qt Quick Examples - Threading</h1>
<span class="subtitle"></span>
<!-- $$$threading-description -->
<div class="descr"> <a name="details"></a>
<p>This is a collection of QML Multithreading examples.<p class="centerAlign"><img src="images/qml-threading-example.png" alt="" /></p><p>Threaded <a href="qtquick-modelviewsdata-modelview.html#listmodel">ListModel</a> contains a <a href="qml-qtquick-listview.html">ListView</a> and a <a href="qtquick-modelviewsdata-modelview.html#listmodel">ListModel</a>. The <a href="qtquick-modelviewsdata-modelview.html#listmodel">ListModel</a> is updated asynchronusly in another thread, and the results propagate back to the main thread. A timer requests updates from the worker thread periodically:</p>
<pre class="qml">        <span class="type">Timer</span> {
            <span class="name">id</span>: <span class="name">timer</span>
            <span class="name">interval</span>: <span class="number">2000</span>; <span class="name">repeat</span>: <span class="number">true</span>
            <span class="name">running</span>: <span class="number">true</span>
            <span class="name">triggeredOnStart</span>: <span class="number">true</span>

            <span class="name">onTriggered</span>: {
                var <span class="name">msg</span> = {'action': <span class="string">'appendCurrentTime'</span>, 'model': <span class="name">listModel</span>};
                <span class="name">worker</span>.<span class="name">sendMessage</span>(<span class="name">msg</span>);
            }
        }</pre>
<p>Inside the worker thread, the <a href="qtquick-modelviewsdata-modelview.html#listmodel">ListModel</a> is synchronized once the data is finished loading:</p>
<pre class="js"><span class="name">WorkerScript</span>.<span class="name">onMessage</span> <span class="operator">=</span> <span class="keyword">function</span>(<span class="name">msg</span>) {
    <span class="keyword">if</span> (<span class="name">msg</span>.<span class="name">action</span> <span class="operator">==</span> <span class="string">'appendCurrentTime'</span>) {
        var <span class="name">data</span> = {'time': new <span class="name">Date</span>().<span class="name">toTimeString</span>()};
        <span class="name">msg</span>.<span class="name">model</span>.<span class="name">append</span>(<span class="name">data</span>);
        <span class="name">msg</span>.<span class="name">model</span>.<span class="name">sync</span>();   <span class="comment">// updates the changes to the list</span>
    }
}</pre>
<p>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.</p>
<p>When the UI needs another value, a request is sent to the WorkerScript:</p>
<pre class="qml">        <span class="type">Spinner</span> {
            <span class="name">id</span>: <span class="name">rowSpinner</span>
            <span class="name">label</span>: <span class="string">&quot;Row&quot;</span>
            <span class="name">onValueChanged</span>: {
                <span class="name">resultText</span>.<span class="name">text</span> <span class="operator">=</span> <span class="string">&quot;Loading...&quot;</span>;
                <span class="name">myWorker</span>.<span class="name">sendMessage</span>( { row: <span class="name">rowSpinner</span>.<span class="name">value</span>, column: <span class="name">columnSpinner</span>.<span class="name">value</span> } );
            }
        }</pre>
<p>The workerscript then is free to take a really long time to calculate it:</p>
<pre class="js"><span class="name">WorkerScript</span>.<span class="name">onMessage</span> <span class="operator">=</span> <span class="keyword">function</span>(<span class="name">message</span>) {
    <span class="comment">//Calculate result (may take a while, using a naive algorithm)</span>
    var <span class="name">calculatedResult</span> = <span class="name">triangle</span>(<span class="name">message</span>.<span class="name">row</span>, <span class="name">message</span>.<span class="name">column</span>);
    <span class="comment">//Send result back to main thread</span>
    <span class="name">WorkerScript</span>.<span class="name">sendMessage</span>( { row: <span class="name">message</span>.<span class="name">row</span>,
                                column: <span class="name">message</span>.<span class="name">column</span>,
                                result: <span class="name">calculatedResult</span>} );
}</pre>
<p>When it's done, the result returns to the main scene via the WorkerScript type:</p>
<pre class="qml">    <span class="type">WorkerScript</span> {
        <span class="name">id</span>: <span class="name">myWorker</span>
        <span class="name">source</span>: <span class="string">&quot;workerscript.js&quot;</span>

        <span class="name">onMessage</span>: {
            <span class="keyword">if</span> (<span class="name">messageObject</span>.<span class="name">row</span> <span class="operator">==</span> <span class="name">rowSpinner</span>.<span class="name">value</span> <span class="operator">&amp;&amp;</span> <span class="name">messageObject</span>.<span class="name">column</span> <span class="operator">==</span> <span class="name">columnSpinner</span>.<span class="name">value</span>){ <span class="comment">//Not an old result</span>
                <span class="keyword">if</span> (<span class="name">messageObject</span>.<span class="name">result</span> <span class="operator">==</span> -<span class="number">1</span>)
                    <span class="name">resultText</span>.<span class="name">text</span> <span class="operator">=</span> <span class="string">&quot;Column must be &lt;= Row&quot;</span>;
                <span class="keyword">else</span>
                    <span class="name">resultText</span>.<span class="name">text</span> <span class="operator">=</span> <span class="name">messageObject</span>.<span class="name">result</span>;
            }
        }
    }</pre>
<p>Files:</p>
<ul>
<li><a href="qtquick-threading-threading-qml.html">threading/threading.qml</a></li>
<li><a href="qtquick-threading-threadedlistmodel-dataloader-js.html">threading/threadedlistmodel/dataloader.js</a></li>
<li><a href="qtquick-threading-threadedlistmodel-timedisplay-qml.html">threading/threadedlistmodel/timedisplay.qml</a></li>
<li><a href="qtquick-threading-workerscript-spinner-qml.html">threading/workerscript/Spinner.qml</a></li>
<li><a href="qtquick-threading-workerscript-workerscript-js.html">threading/workerscript/workerscript.js</a></li>
<li><a href="qtquick-threading-workerscript-workerscript-qml.html">threading/workerscript/workerscript.qml</a></li>
<li><a href="qtquick-threading-main-cpp.html">threading/main.cpp</a></li>
<li><a href="qtquick-threading-threading-pro.html">threading/threading.pro</a></li>
<li><a href="qtquick-threading-threading-qmlproject.html">threading/threading.qmlproject</a></li>
<li><a href="qtquick-threading-threading-qrc.html">threading/threading.qrc</a></li>
<li><a href="qtquick-threading-threadedlistmodel-threadedlistmodel-qmlproject.html">threading/threadedlistmodel/threadedlistmodel.qmlproject</a></li>
<li><a href="qtquick-threading-workerscript-workerscript-qmlproject.html">threading/workerscript/workerscript.qmlproject</a></li>
</ul>
</div>
<!-- @@@threading -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2013 Digia Plc and/or its
   subsidiaries. Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Digia, Qt and their respective logos are trademarks of Digia Plc     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>