1
<?xml version="1.0" encoding="iso-8859-1"?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
3
<html><head><title>QDeclarativeComponent Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
4
a:link { color: #004faf; text-decoration: none }
5
a:visited { color: #672967; text-decoration: none }
6
td.postheader { font-family: sans-serif }
7
tr.address { font-family: sans-serif }
8
body { background: #ffffff; color: black; }
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QDeclarativeComponent Class Reference<br /><sup><sup>[<a href="qtdeclarative.html">QtDeclarative</a> module]</sup></sup></h1><p>The QDeclarativeComponent class encapsulates a QML component
10
definition. <a href="#details">More...</a></p>
12
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qdeclarativecomponent.html#Status-enum">Status</a></b> { Null, Ready, Loading, Error }</li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qdeclarativecomponent.html#QDeclarativeComponent">__init__</a></b> (<i>self</i>, QDeclarativeEngine, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#QDeclarativeComponent-2">__init__</a></b> (<i>self</i>, QDeclarativeEngine, QString <i>fileName</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#QDeclarativeComponent-3">__init__</a></b> (<i>self</i>, QDeclarativeEngine, QUrl <i>url</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />QObject <b><a href="qdeclarativecomponent.html#beginCreate">beginCreate</a></b> (<i>self</i>, QDeclarativeContext)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#completeCreate">completeCreate</a></b> (<i>self</i>)</li><li><div class="fn" />QObject <b><a href="qdeclarativecomponent.html#create">create</a></b> (<i>self</i>, QDeclarativeContext <i>context</i> = None)</li><li><div class="fn" />QDeclarativeContext <b><a href="qdeclarativecomponent.html#creationContext">creationContext</a></b> (<i>self</i>)</li><li><div class="fn" />list-of-QDeclarativeError <b><a href="qdeclarativecomponent.html#errors">errors</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdeclarativecomponent.html#isError">isError</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdeclarativecomponent.html#isLoading">isLoading</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdeclarativecomponent.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qdeclarativecomponent.html#isReady">isReady</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#loadUrl">loadUrl</a></b> (<i>self</i>, QUrl <i>url</i>)</li><li><div class="fn" />float <b><a href="qdeclarativecomponent.html#progress">progress</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#setData">setData</a></b> (<i>self</i>, QByteArray, QUrl <i>baseUrl</i>)</li><li><div class="fn" />Status <b><a href="qdeclarativecomponent.html#status">status</a></b> (<i>self</i>)</li><li><div class="fn" />QUrl <b><a href="qdeclarativecomponent.html#url">url</a></b> (<i>self</i>)</li></ul><h3>Qt Signals</h3><ul><li><div class="fn" />void <b><a href="qdeclarativecomponent.html#progressChanged">progressChanged</a></b> (qreal)</li><li><div class="fn" />void <b><a href="qdeclarativecomponent.html#statusChanged">statusChanged</a></b> (QDeclarativeComponent::Status)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QDeclarativeComponent class encapsulates a QML component
14
<p>Components are reusable, encapsulated QML elements with
15
well-defined interfaces. They are often defined in <a href="qdeclarativedocuments.html">Component Files</a>.</p>
16
<p>A QDeclarativeComponent instance can be created from a QML file.
17
For example, if there is a <tt>main.qml</tt> file like this:</p>
18
<pre class="highlightedCode brush: cpp">
26
<p>The following code loads this QML file as a component, creates
27
an instance of this component using <a href="qdeclarativecomponent.html#create">create</a>(), and then queries
28
the <a href="qml-item.html">Item</a>'s <a href="qml-item.html#width-prop">width</a> value:</p>
29
<pre class="highlightedCode brush: cpp">
30
QDeclarativeEngine *engine = new QDeclarativeEngine;
31
QDeclarativeComponent component(engine, QUrl.fromLocalFile("main.qml"));
33
QObject *myObject = component.create();
34
QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(myObject);
35
int width = item->width(); <span class="comment">// width = 200</span>
36
</pre><hr /><h2>Type Documentation</h2><h3 class="fn"><a name="Status-enum" />QDeclarativeComponent.Status</h3><p>Specifies the loading status of the <a href="qdeclarativecomponent.html">QDeclarativeComponent</a>.</p>
37
<table class="valuelist">
42
<th class="tblConst">Constant</th>
43
<th class="tblval">Value</th>
44
<th class="tbldscr">Description</th>
47
<td class="topAlign"><tt>QDeclarativeComponent.Null</tt></td>
48
<td class=" topAlign"><tt>0</tt></td>
49
<td class="topAlign">This <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> has no data.
50
Call <a href="qdeclarativecomponent.html#loadUrl">loadUrl</a>() or
51
<a href="qdeclarativecomponent.html#setData">setData</a>() to add
55
<td class="topAlign"><tt>QDeclarativeComponent.Ready</tt></td>
56
<td class=" topAlign"><tt>1</tt></td>
57
<td class="topAlign">This <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> is ready and
58
<a href="qdeclarativecomponent.html#create">create</a>() may be
62
<td class="topAlign"><tt>QDeclarativeComponent.Loading</tt></td>
63
<td class=" topAlign"><tt>2</tt></td>
64
<td class="topAlign">This <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> is loading
68
<td class="topAlign"><tt>QDeclarativeComponent.Error</tt></td>
69
<td class=" topAlign"><tt>3</tt></td>
70
<td class="topAlign">An error has occurred. Call <a href="qdeclarativecomponent.html#errors">errors</a>() to retrieve a list
71
of {<a href="qdeclarativeerror.html">QDeclarativeError</a>}{errors}.</td>
74
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QDeclarativeComponent" />QDeclarativeComponent.__init__ (<i>self</i>, <a href="qdeclarativeengine.html">QDeclarativeEngine</a>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Create a <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> with no data
75
and give it the specified <i>engine</i> and <i>parent</i>. Set the
76
data with <a href="qdeclarativecomponent.html#setData">setData</a>().</p>
79
<h3 class="fn"><a name="QDeclarativeComponent-2" />QDeclarativeComponent.__init__ (<i>self</i>, <a href="qdeclarativeengine.html">QDeclarativeEngine</a>, QString <i>fileName</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><h3 class="fn"><a name="QDeclarativeComponent-3" />QDeclarativeComponent.__init__ (<i>self</i>, <a href="qdeclarativeengine.html">QDeclarativeEngine</a>, <a href="qurl.html">QUrl</a> <i>url</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Create a <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> from the
80
given <i>fileName</i> and give it the specified <i>parent</i> and
82
<p>See also <a href="qdeclarativecomponent.html#loadUrl">loadUrl</a>().</p>
85
<h3 class="fn"><a name="beginCreate" /><a href="qobject.html">QObject</a> QDeclarativeComponent.beginCreate (<i>self</i>, <a href="qdeclarativecontext.html">QDeclarativeContext</a>)</h3><p>This method provides more advanced control over component
86
instance creation. In general, programmers should use <a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>()
87
to create a component.</p>
88
<p>Create an object instance from this component. Returns 0 if
89
creation failed. <i>context</i> specifies the context within which
90
to create the object instance.</p>
91
<p>When <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> constructs
92
an instance, it occurs in three steps:</p>
94
<li>The object hierarchy is created, and constant values are
96
<li>Property bindings are evaluated for the the first time.</li>
97
<li>If applicable, <a href="qdeclarativeparserstatus.html#componentComplete">QDeclarativeParserStatus.componentComplete</a>()
98
is called on objects.</li>
100
<p>QDeclarativeComponent.beginCreate() differs from <a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>()
101
in that it only performs step 1. <a href="qdeclarativecomponent.html#completeCreate">QDeclarativeComponent.completeCreate</a>()
102
must be called to complete steps 2 and 3.</p>
103
<p>This breaking point is sometimes useful when using attached
104
properties to communicate information to an instantiated component,
105
as it allows their initial values to be configured before property
106
bindings take effect.</p>
109
<h3 class="fn"><a name="completeCreate" />QDeclarativeComponent.completeCreate (<i>self</i>)</h3><p>This method provides more advanced control over component
110
instance creation. In general, programmers should use <a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>()
111
to create a component.</p>
112
<p>Complete a component creation begin with <a href="qdeclarativecomponent.html#beginCreate">QDeclarativeComponent.beginCreate</a>().</p>
115
<h3 class="fn"><a name="create" /><a href="qobject.html">QObject</a> QDeclarativeComponent.create (<i>self</i>, <a href="qdeclarativecontext.html">QDeclarativeContext</a> <i>context</i> = None)</h3><p>Create an object instance from this component. Returns 0 if
116
creation failed. <i>context</i> specifies the context within which
117
to create the object instance.</p>
118
<p>If <i>context</i> is 0 (the default), it will create the
119
instance in the engine' s <a href="qdeclarativeengine.html#rootContext">root context</a>.</p>
122
<h3 class="fn"><a name="creationContext" /><a href="qdeclarativecontext.html">QDeclarativeContext</a> QDeclarativeComponent.creationContext (<i>self</i>)</h3><p>Returns the <a href="qdeclarativecontext.html">QDeclarativeContext</a> the component
123
was created in. This is only valid for components created directly
127
<h3 class="fn"><a name="errors" />list-of-QDeclarativeError QDeclarativeComponent.errors (<i>self</i>)</h3><p>Return the list of errors that occurred during the last compile
128
or create operation. An empty list is returned if <a href="qdeclarativecomponent.html#isError">isError</a>() is not set.</p>
131
<h3 class="fn"><a name="isError" />bool QDeclarativeComponent.isError (<i>self</i>)</h3><p>Returns true if <a href="qdeclarativecomponent.html#status-prop">status</a>() == <a href="qdeclarativecomponent.html#Status-enum">QDeclarativeComponent.Error</a>.</p>
134
<h3 class="fn"><a name="isLoading" />bool QDeclarativeComponent.isLoading (<i>self</i>)</h3><p>Returns true if <a href="qdeclarativecomponent.html#status-prop">status</a>() == <a href="qdeclarativecomponent.html#Status-enum">QDeclarativeComponent.Loading</a>.</p>
137
<h3 class="fn"><a name="isNull" />bool QDeclarativeComponent.isNull (<i>self</i>)</h3><p>Returns true if <a href="qdeclarativecomponent.html#status-prop">status</a>() == <a href="qdeclarativecomponent.html#Status-enum">QDeclarativeComponent.Null</a>.</p>
140
<h3 class="fn"><a name="isReady" />bool QDeclarativeComponent.isReady (<i>self</i>)</h3><p>Returns true if <a href="qdeclarativecomponent.html#status-prop">status</a>() == <a href="qdeclarativecomponent.html#Status-enum">QDeclarativeComponent.Ready</a>.</p>
143
<h3 class="fn"><a name="loadUrl" />QDeclarativeComponent.loadUrl (<i>self</i>, <a href="qurl.html">QUrl</a> <i>url</i>)</h3><p>Load the <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> from the
144
provided <i>url</i>.</p>
145
<p>Ensure that the URL provided is full and correct, in particular,
146
use <a href="qurl.html#fromLocalFile">QUrl.fromLocalFile</a>()
147
when loading a file from the local filesystem.</p>
150
<h3 class="fn"><a name="progress" />float QDeclarativeComponent.progress (<i>self</i>)</h3><h3 class="fn"><a name="setData" />QDeclarativeComponent.setData (<i>self</i>, <a href="qbytearray.html">QByteArray</a>, <a href="qurl.html">QUrl</a> <i>baseUrl</i>)</h3><p>Sets the <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> to use the
151
given QML <i>data</i>. If <i>url</i> is provided, it is used to set
152
the component name and to provide a base path for items resolved by
156
<h3 class="fn"><a name="status" /><a href="qdeclarativecomponent.html#Status-enum">Status</a> QDeclarativeComponent.status (<i>self</i>)</h3><h3 class="fn"><a name="url" /><a href="qurl.html">QUrl</a> QDeclarativeComponent.url (<i>self</i>)</h3><hr /><h2>Qt Signal Documentation</h2><h3 class="fn"><a name="progressChanged" />void progressChanged (qreal)</h3><p>This is the default overload of this signal.</p><p>Emitted whenever the component's loading progress changes.
157
<i>progress</i> will be the current progress between 0.0 (nothing
158
loaded) and 1.0 (finished).</p>
161
<h3 class="fn"><a name="statusChanged" />void statusChanged (QDeclarativeComponent::Status)</h3><p>This is the default overload of this signal.</p><p>Emitted whenever the component's status changes. <i>status</i>
162
will be the new status.</p>
163
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.8.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.7.0</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'