<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html><head><title>QDeclarativeComponent Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm } a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none } td.postheader { font-family: sans-serif } tr.address { font-family: sans-serif } body { background: #ffffff; color: black; } </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 definition. <a href="#details">More...</a></p> <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 definition.</p> <p>Components are reusable, encapsulated QML elements with well-defined interfaces. They are often defined in <a href="qdeclarativedocuments.html">Component Files</a>.</p> <p>A QDeclarativeComponent instance can be created from a QML file. For example, if there is a <tt>main.qml</tt> file like this:</p> <pre class="highlightedCode brush: cpp"> import QtQuick 1.0 Item { width: 200 height: 200 } </pre> <p>The following code loads this QML file as a component, creates an instance of this component using <a href="qdeclarativecomponent.html#create">create</a>(), and then queries the <a href="qml-item.html">Item</a>'s <a href="qml-item.html#width-prop">width</a> value:</p> <pre class="highlightedCode brush: cpp"> QDeclarativeEngine *engine = new QDeclarativeEngine; QDeclarativeComponent component(engine, QUrl.fromLocalFile("main.qml")); QObject *myObject = component.create(); QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(myObject); int width = item->width(); <span class="comment">// width = 200</span> </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> <table class="valuelist"> <tr class="odd"> <td /> </tr> <tr> <th class="tblConst">Constant</th> <th class="tblval">Value</th> <th class="tbldscr">Description</th> </tr> <tr> <td class="topAlign"><tt>QDeclarativeComponent.Null</tt></td> <td class=" topAlign"><tt>0</tt></td> <td class="topAlign">This <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> has no data. Call <a href="qdeclarativecomponent.html#loadUrl">loadUrl</a>() or <a href="qdeclarativecomponent.html#setData">setData</a>() to add QML content.</td> </tr> <tr> <td class="topAlign"><tt>QDeclarativeComponent.Ready</tt></td> <td class=" topAlign"><tt>1</tt></td> <td class="topAlign">This <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> is ready and <a href="qdeclarativecomponent.html#create">create</a>() may be called.</td> </tr> <tr> <td class="topAlign"><tt>QDeclarativeComponent.Loading</tt></td> <td class=" topAlign"><tt>2</tt></td> <td class="topAlign">This <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> is loading network data.</td> </tr> <tr> <td class="topAlign"><tt>QDeclarativeComponent.Error</tt></td> <td class=" topAlign"><tt>3</tt></td> <td class="topAlign">An error has occurred. Call <a href="qdeclarativecomponent.html#errors">errors</a>() to retrieve a list of {<a href="qdeclarativeerror.html">QDeclarativeError</a>}{errors}.</td> </tr> </table> <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 and give it the specified <i>engine</i> and <i>parent</i>. Set the data with <a href="qdeclarativecomponent.html#setData">setData</a>().</p> <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 given <i>fileName</i> and give it the specified <i>parent</i> and <i>engine</i>.</p> <p>See also <a href="qdeclarativecomponent.html#loadUrl">loadUrl</a>().</p> <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 instance creation. In general, programmers should use <a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>() to create a component.</p> <p>Create an object instance from this component. Returns 0 if creation failed. <i>context</i> specifies the context within which to create the object instance.</p> <p>When <a href="qdeclarativecomponent.html">QDeclarativeComponent</a> constructs an instance, it occurs in three steps:</p> <ol class="1"> <li>The object hierarchy is created, and constant values are assigned.</li> <li>Property bindings are evaluated for the the first time.</li> <li>If applicable, <a href="qdeclarativeparserstatus.html#componentComplete">QDeclarativeParserStatus.componentComplete</a>() is called on objects.</li> </ol> <p>QDeclarativeComponent.beginCreate() differs from <a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>() in that it only performs step 1. <a href="qdeclarativecomponent.html#completeCreate">QDeclarativeComponent.completeCreate</a>() must be called to complete steps 2 and 3.</p> <p>This breaking point is sometimes useful when using attached properties to communicate information to an instantiated component, as it allows their initial values to be configured before property bindings take effect.</p> <h3 class="fn"><a name="completeCreate" />QDeclarativeComponent.completeCreate (<i>self</i>)</h3><p>This method provides more advanced control over component instance creation. In general, programmers should use <a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>() to create a component.</p> <p>Complete a component creation begin with <a href="qdeclarativecomponent.html#beginCreate">QDeclarativeComponent.beginCreate</a>().</p> <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 creation failed. <i>context</i> specifies the context within which to create the object instance.</p> <p>If <i>context</i> is 0 (the default), it will create the instance in the engine' s <a href="qdeclarativeengine.html#rootContext">root context</a>.</p> <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 was created in. This is only valid for components created directly from QML.</p> <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 or create operation. An empty list is returned if <a href="qdeclarativecomponent.html#isError">isError</a>() is not set.</p> <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> <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> <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> <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> <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 provided <i>url</i>.</p> <p>Ensure that the URL provided is full and correct, in particular, use <a href="qurl.html#fromLocalFile">QUrl.fromLocalFile</a>() when loading a file from the local filesystem.</p> <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 given QML <i>data</i>. If <i>url</i> is provided, it is used to set the component name and to provide a base path for items resolved by this component.</p> <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. <i>progress</i> will be the current progress between 0.0 (nothing loaded) and 1.0 (finished).</p> <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> will be the new status.</p> <address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.8.3 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> 2011</td><td align="right" width="25%">Qt 4.7.1</td></tr></table></div></address></body></html>