This file is indexed.

/usr/share/qt5/doc/qtquick/qml-qtquick-loader.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
<?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" />
<!-- qquickloader.cpp -->
  <title>Loader | 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><a href="qtquick-qmltypereference.html">QML Types</a></li>
<li>Loader</li>
<li id="buildversion">
Qt 5.2.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#properties">Properties</a></li>
<li class="level1"><a href="#signals">Signals</a></li>
<li class="level1"><a href="#methods">Methods</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#loader-sizing-behavior">Loader sizing behavior</a></li>
<li class="level2"><a href="#receiving-signals-from-loaded-objects">Receiving signals from loaded objects</a></li>
<li class="level2"><a href="#focus-and-key-events">Focus and key events</a></li>
<li class="level2"><a href="#using-a-loader-within-a-view-delegate">Using a Loader within a view delegate</a></li>
</ul>
</div>
<h1 class="title">Loader</h1>
<span class="subtitle"></span>
<!-- $$$Loader-brief -->
<p>Allows dynamic loading of a subtree from a URL or Component <a href="#details">More...</a></p>
<!-- @@@Loader -->
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Import Statement:</td><td class="memItemRight bottomAlign"> </b><tt>import QtQuick 2.2</tt></td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <p><a href="qml-qtquick-item.html">Item</a></p>
</td></tr></table><ul>
<li><a href="qml-qtquick-loader-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h2>Properties</h2>
<ul>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#active-prop">active</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#asynchronous-prop">asynchronous</a></b></b> : bool</li>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#item-prop">item</a></b></b> : object</li>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#progress-prop">progress</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#source-prop">source</a></b></b> : url</li>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a></b></b> : Component</li>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#status-prop">status</a></b></b> : enumeration</li>
</ul>
<a name="signals"></a>
<h2>Signals</h2>
<ul>
<li class="fn"><b><b><a href="qml-qtquick-loader.html#onLoaded-signal">onLoaded</a></b></b>()</li>
</ul>
<a name="methods"></a>
<h2>Methods</h2>
<ul>
<li class="fn">object <b><b><a href="qml-qtquick-loader.html#setSource-method">setSource</a></b></b>(url <i>source</i>, object <i>properties</i>)</li>
</ul>
<!-- $$$Loader-description -->
<a name="details"></a>
<h2>Detailed Description</h2>
<p>Loader is used to dynamically load QML components.</p>
<p>Loader can load a QML file (using the <a href="qml-qtquick-loader.html#source-prop">source</a> property) or a Component object (using the <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a> property). It is useful for delaying the creation of a component until it is required: for example, when a component should be created on demand, or when a component should not be created unnecessarily for performance reasons.</p>
<p>Here is a Loader that loads &quot;Page1.qml&quot; as a component when the <a href="qml-qtquick-mousearea.html">MouseArea</a> is clicked:</p>
<pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">200</span>

    <span class="type">Loader</span> { <span class="name">id</span>: <span class="name">pageLoader</span> }

    <span class="type"><a href="qml-qtquick-mousearea.html">MouseArea</a></span> {
        <span class="name">anchors</span>.fill: <span class="name">parent</span>
        <span class="name">onClicked</span>: <span class="name">pageLoader</span>.<span class="name">source</span> <span class="operator">=</span> <span class="string">&quot;Page1.qml&quot;</span>
    }
}</pre>
<p>The loaded object can be accessed using the <a href="qml-qtquick-loader.html#item-prop">item</a> property.</p>
<p>If the <a href="qml-qtquick-loader.html#source-prop">source</a> or <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a> changes, any previously instantiated items are destroyed. Setting <a href="qml-qtquick-loader.html#source-prop">source</a> to an empty string or setting <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a> to <tt>undefined</tt> destroys the currently loaded object, freeing resources and leaving the Loader empty.</p>
<a name="loader-sizing-behavior"></a>
<h3>Loader sizing behavior</h3>
<p>If the source component is not an Item type, Loader does not apply any special sizing rules. When used to load visual types, Loader applies the following sizing rules:</p>
<ul>
<li>If an explicit size is not specified for the Loader, the Loader is automatically resized to the size of the loaded item once the component is loaded.</li>
<li>If the size of the Loader is specified explicitly by setting the width, height or by anchoring, the loaded item will be resized to the size of the Loader.</li>
</ul>
<p>In both scenarios the size of the item and the Loader are identical. This ensures that anchoring to the Loader is equivalent to anchoring to the loaded item.</p>
<table class="generic">
 <tr valign="top" class="odd"><td >sizeloader.qml</td><td >sizeitem.qml</td></tr>
<tr valign="top" class="even"><td ><pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">200</span>

    <span class="type">Loader</span> {
        <span class="comment">// Explicitly set the size of the Loader to the parent item's size</span>
        <span class="name">anchors</span>.fill: <span class="name">parent</span>
        <span class="name">sourceComponent</span>: <span class="name">rect</span>
    }

    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">rect</span>
        <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
            <span class="name">width</span>: <span class="number">50</span>
            <span class="name">height</span>: <span class="number">50</span>
            <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
        }
    }
}</pre>
</td><td ><pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">200</span>

    <span class="type">Loader</span> {
        <span class="comment">// position the Loader in the center of the parent</span>
        <span class="name">anchors</span>.centerIn: <span class="name">parent</span>
        <span class="name">sourceComponent</span>: <span class="name">rect</span>
    }

    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">rect</span>
        <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
            <span class="name">width</span>: <span class="number">50</span>
            <span class="name">height</span>: <span class="number">50</span>
            <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
        }
    }
}</pre>
</td></tr>
<tr valign="top" class="odd"><td >The red rectangle will be sized to the size of the root item.</td><td >The red rectangle will be 50x50, centered in the root item.</td></tr>
</table>
<a name="receiving-signals-from-loaded-objects"></a>
<h3>Receiving signals from loaded objects</h3>
<p>Any signals emitted from the loaded object can be received using the Connections type. For example, the following <tt>application.qml</tt> loads <tt>MyItem.qml</tt>, and is able to receive the <tt>message</tt> signal from the loaded item through a Connections object:</p>
<table class="generic">
 <tr valign="top" class="odd"><td >application.qml</td><td >MyItem.qml</td></tr>
<tr valign="top" class="even"><td ><pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>

    <span class="type">Loader</span> {
       <span class="name">id</span>: <span class="name">myLoader</span>
       <span class="name">source</span>: <span class="string">&quot;MyItem.qml&quot;</span>
    }

    <span class="type">Connections</span> {
        <span class="name">target</span>: <span class="name">myLoader</span>.<span class="name">item</span>
        <span class="name">onMessage</span>: <span class="name">console</span>.<span class="name">log</span>(<span class="name">msg</span>)
    }
}</pre>
</td><td ><pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
   <span class="name">id</span>: <span class="name">myItem</span>
   signal <span class="type">message</span>(string msg)

   <span class="name">width</span>: <span class="number">100</span>; <span class="name">height</span>: <span class="number">100</span>

   <span class="type"><a href="qml-qtquick-mousearea.html">MouseArea</a></span> {
       <span class="name">anchors</span>.fill: <span class="name">parent</span>
       <span class="name">onClicked</span>: <span class="name">myItem</span>.<span class="name">message</span>(<span class="string">&quot;clicked!&quot;</span>)
   }
}</pre>
</td></tr>
</table>
<p>Alternatively, since <tt>MyItem.qml</tt> is loaded within the scope of the Loader, it could also directly call any function defined in the Loader or its parent <a href="qml-qtquick-item.html">Item</a>.</p>
<a name="focus-and-key-events"></a>
<h3>Focus and key events</h3>
<p>Loader is a focus scope. Its <a href="qml-qtquick-item.html#focus-prop">focus</a> property must be set to <tt>true</tt> for any of its children to get the <i>active focus</i>. (See <a href="qtquick-input-focus.html">Keyboard Focus in Qt Quick</a> for more details.) Any key events received in the loaded item should likely also be <a href="qml-qtquick-keyevent.html#accepted-prop">accepted</a> so they are not propagated to the Loader.</p>
<p>For example, the following <tt>application.qml</tt> loads <tt>KeyReader.qml</tt> when the <a href="qml-qtquick-mousearea.html">MouseArea</a> is clicked. Notice the <a href="qml-qtquick-item.html#focus-prop">focus</a> property is set to <tt>true</tt> for the Loader as well as the <a href="qml-qtquick-item.html">Item</a> in the dynamically loaded object:</p>
<table class="generic">
 <tr valign="top" class="odd"><td >application.qml</td><td >KeyReader.qml</td></tr>
<tr valign="top" class="even"><td ><pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
    <span class="name">width</span>: <span class="number">200</span>; <span class="name">height</span>: <span class="number">200</span>

    <span class="type">Loader</span> {
        <span class="name">id</span>: <span class="name">loader</span>
        <span class="name">focus</span>: <span class="number">true</span>
    }

    <span class="type"><a href="qml-qtquick-mousearea.html">MouseArea</a></span> {
        <span class="name">anchors</span>.fill: <span class="name">parent</span>
        <span class="name">onClicked</span>: <span class="name">loader</span>.<span class="name">source</span> <span class="operator">=</span> <span class="string">&quot;KeyReader.qml&quot;</span>
    }

    <span class="name">Keys</span>.onPressed: {
        <span class="name">console</span>.<span class="name">log</span>(<span class="string">&quot;Captured:&quot;</span>, <span class="name">event</span>.<span class="name">text</span>);
    }
}</pre>
</td><td ><pre class="qml">import QtQuick 2.0

<span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
        <span class="name">focus</span>: <span class="number">true</span>
        <span class="name">Keys</span>.onPressed: {
            <span class="name">console</span>.<span class="name">log</span>(<span class="string">&quot;Loaded item captured:&quot;</span>, <span class="name">event</span>.<span class="name">text</span>);
            <span class="name">event</span>.<span class="name">accepted</span> <span class="operator">=</span> <span class="number">true</span>;
        }
    }
}</pre>
</td></tr>
</table>
<p>Once <tt>KeyReader.qml</tt> is loaded, it accepts key events and sets <tt>event.accepted</tt> to <tt>true</tt> so that the event is not propagated to the parent <a href="qml-qtquick-rectangle.html">Rectangle</a>.</p>
<p>Since <tt>QtQuick 2.0</tt>, Loader can also load non-visual components.</p>
<a name="using-a-loader-within-a-view-delegate"></a>
<h3>Using a Loader within a view delegate</h3>
<p>In some cases you may wish to use a Loader within a view delegate to improve delegate loading performance. This works well in most cases, but there is one important issue to be aware of related to the creation context of a Component.</p>
<p>In the following example, the <tt>index</tt> context property inserted by the <a href="qml-qtquick-listview.html">ListView</a> into <tt>delegateComponent</tt>'s context will be inaccessible to Text, as the Loader will use the creation context of <tt>myComponent</tt> as the parent context when instantiating it, and <tt>index</tt> does not refer to anything within that context chain.</p>
<pre class="qml"><span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="name">width</span>: <span class="number">400</span>
    <span class="name">height</span>: <span class="number">400</span>

    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">myComponent</span>
        <span class="type"><a href="qml-qtquick-text.html">Text</a></span> { <span class="name">text</span>: <span class="name">index</span> }    <span class="comment">//fails</span>
    }

    <span class="type"><a href="qml-qtquick-listview.html">ListView</a></span> {
        <span class="name">anchors</span>.fill: <span class="name">parent</span>
        <span class="name">model</span>: <span class="number">5</span>
        <span class="name">delegate</span>: <span class="name">Component</span> {
            <span class="name">id</span>: <span class="name">delegateComponent</span>
            <span class="type">Loader</span> {
                <span class="name">sourceComponent</span>: <span class="name">myComponent</span>
            }
        }
    }
}</pre>
<p>In this situation we can either move the component inline,</p>
<pre class="qml">        <span class="name">delegate</span>: <span class="name">Component</span> {
            <span class="type">Loader</span> {
                <span class="name">sourceComponent</span>: <span class="name">Component</span> {
                    <span class="type"><a href="qml-qtquick-text.html">Text</a></span> { <span class="name">text</span>: <span class="name">index</span> }    <span class="comment">//okay</span>
                }
            }
        }</pre>
<p>into a separate file,</p>
<pre class="qml">        <span class="name">delegate</span>: <span class="name">Component</span> {
            <span class="type">Loader</span> {
                <span class="name">source</span>: <span class="string">&quot;MyComponent.qml&quot;</span> <span class="comment">//okay</span>
            }
        }</pre>
<p>or explicitly set the required information as a property of the Loader (this works because the Loader sets itself as the context object for the component it is loading).</p>
<pre class="qml"><span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="name">width</span>: <span class="number">400</span>
    <span class="name">height</span>: <span class="number">400</span>

    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">myComponent</span>
        <span class="type"><a href="qml-qtquick-text.html">Text</a></span> { <span class="name">text</span>: <span class="name">modelIndex</span> }    <span class="comment">//okay</span>
    }

    <span class="type"><a href="qml-qtquick-listview.html">ListView</a></span> {
        <span class="name">anchors</span>.fill: <span class="name">parent</span>
        <span class="name">model</span>: <span class="number">5</span>
        <span class="name">delegate</span>: <span class="name">Component</span> {
            <span class="type">Loader</span> {
                property <span class="type">int</span> <span class="name">modelIndex</span>: <span class="name">index</span>
                <span class="name">sourceComponent</span>: <span class="name">myComponent</span>
            }
        }
    }
}</pre>
<p><b>See also </b>Dynamic Object Creation.</p>
<!-- @@@Loader -->
<h2>Property Documentation</h2>
<!-- $$$active -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="active-prop"></a><span class="name">active</span> : <span class="type">bool</span></p></td></tr></table></div><div class="qmldoc"><p>This property is <tt>true</tt> if the Loader is currently active. The default value for this property is <tt>true</tt>.</p>
<p>If the Loader is inactive, changing the <a href="qml-qtquick-loader.html#source-prop">source</a> or <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a> will not cause the item to be instantiated until the Loader is made active.</p>
<p>Setting the value to inactive will cause any <a href="qml-qtquick-loader.html#item-prop">item</a> loaded by the loader to be released, but will not affect the <a href="qml-qtquick-loader.html#source-prop">source</a> or <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a>.</p>
<p>The <a href="qml-qtquick-loader.html#status-prop">status</a> of an inactive loader is always <tt>Null</tt>.</p>
<p><b>See also </b><a href="qml-qtquick-loader.html#source-prop">source</a> and <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a>.</p>
</div></div><!-- @@@active -->
<br/>
<!-- $$$asynchronous -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="asynchronous-prop"></a><span class="name">asynchronous</span> : <span class="type">bool</span></p></td></tr></table></div><div class="qmldoc"><p>This property holds whether the component will be instantiated asynchronously.</p>
<p>When used in conjunction with the <a href="qml-qtquick-loader.html#source-prop">source</a> property, loading and compilation will also be performed in a background thread.</p>
<p>Loading asynchronously creates the objects declared by the component across multiple frames, and reduces the likelihood of glitches in animation. When loading asynchronously the status will change to Loader.Loading. Once the entire component has been created, the <a href="qml-qtquick-loader.html#item-prop">item</a> will be available and the status will change to Loader.Ready.</p>
<p>To avoid seeing the items loading progressively set <tt>visible</tt> appropriately, e.g&#x2e;</p>
<pre class="cpp">Loader {
    source: <span class="string">&quot;mycomponent.qml&quot;</span>
    asynchronous: <span class="keyword">true</span>
    visible: status <span class="operator">=</span><span class="operator">=</span> Loader<span class="operator">.</span>Ready
}</pre>
<p>Note that this property affects object instantiation only; it is unrelated to loading a component asynchronously via a network.</p>
</div></div><!-- @@@asynchronous -->
<br/>
<!-- $$$item -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="item-prop"></a><span class="name">item</span> : <span class="type">object</span></p></td></tr></table></div><div class="qmldoc"><p>This property holds the top-level object that is currently loaded.</p>
<p>Since <tt>QtQuick 2.0</tt>, Loader can load any object type.</p>
</div></div><!-- @@@item -->
<br/>
<!-- $$$progress -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="progress-prop"></a><span class="name">progress</span> : <span class="type">real</span></p></td></tr></table></div><div class="qmldoc"><p>This property holds the progress of loading QML data from the network, from 0.0 (nothing loaded) to 1.0 (finished). Most QML files are quite small, so this value will rapidly change from 0 to 1.</p>
<p><b>See also </b><a href="qml-qtquick-loader.html#status-prop">status</a>.</p>
</div></div><!-- @@@progress -->
<br/>
<!-- $$$source -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="source-prop"></a><span class="name">source</span> : <span class="type">url</span></p></td></tr></table></div><div class="qmldoc"><p>This property holds the URL of the QML component to instantiate.</p>
<p>Since <tt>QtQuick 2.0</tt>, Loader is able to load any type of object; it is not restricted to Item types.</p>
<p>To unload the currently loaded object, set this property to an empty string, or set <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a> to <tt>undefined</tt>. Setting <tt>source</tt> to a new URL will also cause the item created by the previous URL to be unloaded.</p>
<p><b>See also </b><a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a>, <a href="qml-qtquick-loader.html#status-prop">status</a>, and <a href="qml-qtquick-loader.html#progress-prop">progress</a>.</p>
</div></div><!-- @@@source -->
<br/>
<!-- $$$sourceComponent -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="sourceComponent-prop"></a><span class="name">sourceComponent</span> : <span class="type">Component</span></p></td></tr></table></div><div class="qmldoc"><p>This property holds the Component to instantiate.</p>
<pre class="qml"><span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="type">Component</span> {
        <span class="name">id</span>: <span class="name">redSquare</span>
        <span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> { <span class="name">color</span>: <span class="string">&quot;red&quot;</span>; <span class="name">width</span>: <span class="number">10</span>; <span class="name">height</span>: <span class="number">10</span> }
    }

    <span class="type"><a href="qml-qtquick-loader.html">Loader</a></span> { <span class="name">sourceComponent</span>: <span class="name">redSquare</span> }
    <span class="type"><a href="qml-qtquick-loader.html">Loader</a></span> { <span class="name">sourceComponent</span>: <span class="name">redSquare</span>; <span class="name">x</span>: <span class="number">10</span> }
}</pre>
<p>To unload the currently loaded object, set this property to an empty string or <tt>undefined</tt>.</p>
<p>Since <tt>QtQuick 2.0</tt>, Loader is able to load any type of object; it is not restricted to Item types.</p>
<p><b>See also </b><a href="qml-qtquick-loader.html#source-prop">source</a> and <a href="qml-qtquick-loader.html#progress-prop">progress</a>.</p>
</div></div><!-- @@@sourceComponent -->
<br/>
<!-- $$$status -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="status-prop"></a><span class="name">status</span> : <span class="type">enumeration</span></p></td></tr></table></div><div class="qmldoc"><p>This property holds the status of QML loading. It can be one of:</p>
<ul>
<li>Loader.Null - the loader is inactive or no QML source has been set</li>
<li>Loader.Ready - the QML source has been loaded</li>
<li>Loader.Loading - the QML source is currently being loaded</li>
<li>Loader.Error - an error occurred while loading the QML source</li>
</ul>
<p>Use this status to provide an update or respond to the status change in some way. For example, you could:</p>
<ul>
<li>Trigger a state change:<pre class="qml"><span class="type"><a href="qml-qtquick-state.html">State</a></span> { <span class="name">name</span>: <span class="string">'loaded'</span>; <span class="name">when</span>: <span class="name">loader</span>.<span class="name">status</span> <span class="operator">==</span> <span class="name">Loader</span>.<span class="name">Ready</span> }</pre>
</li>
<li>Implement an <tt>onStatusChanged</tt> signal handler:<pre class="qml"><span class="type"><a href="qml-qtquick-loader.html">Loader</a></span> {
    <span class="name">id</span>: <span class="name">loader</span>
    <span class="name">onStatusChanged</span>: <span class="keyword">if</span> (<span class="name">loader</span>.<span class="name">status</span> <span class="operator">==</span> <span class="name">Loader</span>.<span class="name">Ready</span>) <span class="name">console</span>.<span class="name">log</span>(<span class="string">'Loaded'</span>)
}</pre>
</li>
<li>Bind to the status value:<pre class="qml"><span class="type"><a href="qml-qtquick-text.html">Text</a></span> { <span class="name">text</span>: <span class="name">loader</span>.<span class="name">status</span> <span class="operator">==</span> <span class="name">Loader</span>.<span class="name">Ready</span> ? <span class="string">'Loaded'</span> : <span class="string">'Not loaded'</span> }</pre>
</li>
</ul>
<p>Note that if the source is a local file, the status will initially be Ready (or Error). While there will be no onStatusChanged signal in that case, the <a href="qml-qtquick-loader.html#onLoaded-signal">onLoaded</a> will still be invoked.</p>
<p><b>See also </b><a href="qml-qtquick-loader.html#progress-prop">progress</a>.</p>
</div></div><!-- @@@status -->
<br/>
<h2>Signal Documentation</h2>
<!-- $$$onLoaded -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlFuncNode"><p><a name="onLoaded-signal"></a><span class="name">onLoaded</span>()</p></td></tr></table></div><div class="qmldoc"><p>This handler is called when the <a href="qml-qtquick-loader.html#status-prop">status</a> becomes <tt>Loader.Ready</tt>, or on successful initial load.</p>
</div></div><!-- @@@onLoaded -->
<br/>
<h2>Method Documentation</h2>
<!-- $$$setSource -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlFuncNode"><p><a name="setSource-method"></a><span class="type">object</span> <span class="name">setSource</span>(<span class="type">url</span><i> source</i>, <span class="type">object</span><i> properties</i>)</p></td></tr></table></div><div class="qmldoc"><p>Creates an object instance of the given <i>source</i> component that will have the given <i>properties</i>. The <i>properties</i> argument is optional. The instance will be accessible via the <a href="qml-qtquick-loader.html#item-prop">item</a> property once loading and instantiation is complete.</p>
<p>If the <a href="qml-qtquick-loader.html#active-prop">active</a> property is <tt>false</tt> at the time when this function is called, the given <i>source</i> component will not be loaded but the <i>source</i> and initial <i>properties</i> will be cached. When the loader is made <a href="qml-qtquick-loader.html#active-prop">active</a>, an instance of the <i>source</i> component will be created with the initial <i>properties</i> set.</p>
<p>Setting the initial property values of an instance of a component in this manner will <b>not</b> trigger any associated <a href="qml-qtquick-behavior.html">Behavior</a>s.</p>
<p>Note that the cached <i>properties</i> will be cleared if the <a href="qml-qtquick-loader.html#source-prop">source</a> or <a href="qml-qtquick-loader.html#sourceComponent-prop">sourceComponent</a> is changed after calling this function but prior to setting the loader <a href="qml-qtquick-loader.html#active-prop">active</a>.</p>
<p>Example:</p>
<table class="generic">
 <tr valign="top" class="odd"><td ><pre class="qml"><span class="comment">// ExampleComponent.qml</span>
import QtQuick 2.0
<span class="type"><a href="qml-qtquick-rectangle.html">Rectangle</a></span> {
    <span class="name">id</span>: <span class="name">rect</span>
    <span class="name">color</span>: <span class="string">&quot;red&quot;</span>
    <span class="name">width</span>: <span class="number">10</span>
    <span class="name">height</span>: <span class="number">10</span>

    Behavior on <span class="name">color</span> {
        <span class="type"><a href="qml-qtquick-numberanimation.html">NumberAnimation</a></span> {
            <span class="name">target</span>: <span class="name">rect</span>
            <span class="name">property</span>: <span class="string">&quot;width&quot;</span>
            <span class="name">to</span>: (<span class="name">rect</span>.<span class="name">width</span> <span class="operator">+</span> <span class="number">20</span>)
            <span class="name">duration</span>: <span class="number">0</span>
        }
    }
}</pre>
</td><td ><pre class="qml"><span class="comment">// example.qml</span>
import QtQuick 2.0
<span class="type"><a href="qml-qtquick-item.html">Item</a></span> {
    <span class="type"><a href="qml-qtquick-loader.html">Loader</a></span> {
        <span class="name">id</span>: <span class="name">squareLoader</span>
        <span class="name">onLoaded</span>: <span class="name">console</span>.<span class="name">log</span>(<span class="name">squareLoader</span>.<span class="name">item</span>.<span class="name">width</span>); <span class="comment">// prints [10], not [30]</span>
    }

    <span class="name">Component</span>.onCompleted: {
        <span class="name">squareLoader</span>.<span class="name">setSource</span>(<span class="string">&quot;ExampleComponent.qml&quot;</span>, { &quot;color&quot;: <span class="string">&quot;blue&quot;</span> });
        <span class="comment">// will trigger the onLoaded code when complete.</span>
    }
}</pre>
</td></tr>
</table>
<p><b>See also </b><a href="qml-qtquick-loader.html#source-prop">source</a> and <a href="qml-qtquick-loader.html#active-prop">active</a>.</p>
</div></div><!-- @@@setSource -->
<br/>
        </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>