Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > 28b9e36e96ce34b2567ae5b47a27b2c5 > files > 589

python-qt4-doc-4.10.3-3.mga4.noarch.rpm

<?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">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <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&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#QDeclarativeComponent-2">__init__</a></b> (<i>self</i>, QDeclarativeEngine, QString&#160;<i>fileName</i>, QObject&#160;<i>parent</i>&#160;=&#160;None)</li><li><div class="fn" /><b><a href="qdeclarativecomponent.html#QDeclarativeComponent-3">__init__</a></b> (<i>self</i>, QDeclarativeEngine, QUrl&#160;<i>url</i>, QObject&#160;<i>parent</i>&#160;=&#160;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&#160;<i>context</i>&#160;=&#160;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&#160;<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&#160;<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="qml">
 import QtQuick 1.0

 <span class="type"><a href="qml-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>
 }
</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="cpp">
 <span class="type"><a href="qdeclarativeengine.html">QDeclarativeEngine</a></span> <span class="operator">*</span>engine <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qdeclarativeengine.html">QDeclarativeEngine</a></span>;
 <span class="type">QDeclarativeComponent</span> component(engine<span class="operator">,</span> <span class="type"><a href="qurl.html">QUrl</a></span><span class="operator">.</span>fromLocalFile(<span class="string">"main.qml"</span>));

 <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>myObject <span class="operator">=</span> component<span class="operator">.</span><a href="qdeclarativecomponent.html#create">create</a>();
 <span class="type"><a href="qdeclarativeitem.html">QDeclarativeItem</a></span> <span class="operator">*</span>item <span class="operator">=</span> qobject_cast<span class="operator">&lt;</span><span class="type"><a href="qdeclarativeitem.html">QDeclarativeItem</a></span><span class="operator">*</span><span class="operator">&gt;</span>(myObject);
 <span class="type">int</span> width <span class="operator">=</span> item<span class="operator">-</span><span class="operator">&gt;</span>width();  <span class="comment">// width = 200</span>
</pre>
<a id="network-components" name="network-components" />
<h4>Network Components</h4>
<p>If the URL passed to QDeclarativeComponent is a network
resource, or if the QML document references a network resource, the
QDeclarativeComponent has to fetch the network data before it is
able to create objects. In this case, the QDeclarativeComponent
will have a <a href="qdeclarativecomponent.html#Status-enum">Loading</a> <a href="qdeclarativecomponent.html#status-prop">status</a>. An application
will have to wait until the component is <a href="qdeclarativecomponent.html#Status-enum">Ready</a> before calling
<a href="qdeclarativecomponent.html#create">QDeclarativeComponent.create</a>().</p>
<p>The following example shows how to load a QML file from a
network resource. After creating the QDeclarativeComponent, it
tests whether the component is loading. If it is, it connects to
the <a href="qdeclarativecomponent.html#statusChanged">QDeclarativeComponent.statusChanged</a>()
signal and otherwise calls the <tt>continueLoading()</tt> method
directly. Note that <a href="qdeclarativecomponent.html#isLoading">QDeclarativeComponent.isLoading</a>()
may be false for a network component if the component has been
cached and is ready immediately.</p>
<pre class="cpp">
 MyApplication<span class="operator">.</span>MyApplication()
 {
     <span class="comment">// ...</span>
     component <span class="operator">=</span> <span class="keyword">new</span> <span class="type">QDeclarativeComponent</span>(engine<span class="operator">,</span> <span class="type"><a href="qurl.html">QUrl</a></span>(<span class="string">"http://www.example.com/main.qml"</span>));
     <span class="keyword">if</span> (component<span class="operator">-</span><span class="operator">&gt;</span>isLoading())
         <span class="type"><a href="qobject.html">QObject</a></span><span class="operator">.</span>connect(component<span class="operator">,</span> SIGNAL(statusChanged(<span class="type">QDeclarativeComponent</span><span class="operator">.</span>Status))<span class="operator">,</span>
                          <span class="keyword">this</span><span class="operator">,</span> SLOT(continueLoading()));
     <span class="keyword">else</span>
         continueLoading();
 }

 <span class="type">void</span> MyApplication<span class="operator">.</span>continueLoading()
 {
     <span class="keyword">if</span> (component<span class="operator">-</span><span class="operator">&gt;</span>isError()) {
         <a href="qtcore.html#qWarning">qWarning</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> component<span class="operator">-</span><span class="operator">&gt;</span>errors();
     } <span class="keyword">else</span> {
         <span class="type"><a href="qobject.html">QObject</a></span> <span class="operator">*</span>myObject <span class="operator">=</span> component<span class="operator">-</span><span class="operator">&gt;</span>create();
     }
 }
</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" valign="top">
<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>&#160;<i>parent</i>&#160;=&#160;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&#160;<i>fileName</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;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>&#160;<i>url</i>, <a href="qobject.html">QObject</a>&#160;<i>parent</i>&#160;=&#160;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><b>See also</b> <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>&#160;<i>context</i>&#160;=&#160;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>&#160;<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>&#160;<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&#160;4.10.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.5</td></tr></table></div></address></body></html>