Sophie

Sophie

distrib > Fedora > 18 > x86_64 > by-pkgid > ff187cb994c94c614ecc64c5a8528b1b > files > 5797

qt-doc-4.8.5-10.fc18.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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" />
<!-- qdeclarativecomponent.cpp -->
  <title>Qt 4.8: QML Component Element</title>
  <link rel="stylesheet" type="text/css" href="style/style.css" />
  <script src="scripts/jquery.js" type="text/javascript"></script>
  <script src="scripts/functions.js" type="text/javascript"></script>
  <link rel="stylesheet" type="text/css" href="style/superfish.css" />
  <link rel="stylesheet" type="text/css" href="style/narrow.css" />
  <!--[if IE]>
<meta name="MSSmartTagsPreventParsing" content="true">
<meta http-equiv="imagetoolbar" content="no">
<![endif]-->
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie6.css">
<![endif]-->
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="style/style_ie7.css">
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" type="text/css" href="style/style_ie8.css">
<![endif]-->

<script src="scripts/superfish.js" type="text/javascript"></script>
<script src="scripts/narrow.js" type="text/javascript"></script>

</head>
<body class="" onload="CheckEmptyAndLoadList();">
 <div class="header" id="qtdocheader">
    <div class="content"> 
    <div id="nav-logo">
      <a href="index.html">Home</a></div>
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
    <div id="narrowsearch"></div>
    <div id="nav-topright">
      <ul>
        <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li>
        <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li>
        <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/">
          DOC</a></li>
        <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li>
      </ul>
    </div>
    <div id="shortCut">
      <ul>
        <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li>
        <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS        </a></li>
      </ul>
     </div>
 <ul class="sf-menu" id="narrowmenu"> 
             <li><a href="#">API Lookup</a> 
                 <ul> 
                     <li><a href="classes.html">Class index</a></li> 
           <li><a href="functions.html">Function index</a></li> 
           <li><a href="modules.html">Modules</a></li> 
           <li><a href="namespaces.html">Namespaces</a></li> 
           <li><a href="qtglobal.html">Global Declarations</a></li> 
           <li><a href="qdeclarativeelements.html">QML elements</a></li> 
             </ul> 
             </li> 
             <li><a href="#">Qt Topics</a> 
                 <ul> 
                        <li><a href="qt-basic-concepts.html">Programming with Qt</a></li>  
                        <li><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li>  
                        <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li>  
                        <li><a href="supported-platforms.html">Supported Platforms</a></li>  
                        <li><a href="technology-apis.html">Qt and Key Technologies</a></li>  
                        <li><a href="best-practices.html">How-To's and Best Practices</a></li>  
              </ul> 
                 </li> 
                 <li><a href="#">Examples</a> 
                     <ul> 
                       <li><a href="all-examples.html">Examples</a></li> 
                       <li><a href="tutorials.html">Tutorials</a></li> 
                       <li><a href="demos.html">Demos</a></li> 
                       <li><a href="qdeclarativeexamples.html">QML Examples</a></li> 
                </ul> 
                     </li> 
                 </ul> 
    </div>
  </div>
  <div class="wrapper">
    <div class="hd">
      <span></span>
    </div>
    <div class="bd group">
      <div class="sidebar">
        <div class="searchlabel">
          Search index:</div>
        <div class="search" id="sidebarsearch">
          <form id="qtdocsearch" action="" onsubmit="return false;">
            <fieldset>
              <input type="text" name="searchstring" id="pageType" value="" />
 <div id="resultdialog"> 
 <a href="#" id="resultclose">Close</a> 
 <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> 
 <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span>&nbsp;results:</p> 
 <ul id="resultlist" class="all"> 
 </ul> 
 </div> 
            </fieldset>
          </form>
        </div>
        <div class="box first bottombar" id="lookup">
          <h2 title="API Lookup"><span></span>
            API Lookup</h2>
          <div  id="list001" class="list">
          <ul id="ul001" >
              <li class="defaultLink"><a href="classes.html">Class index</a></li>
              <li class="defaultLink"><a href="functions.html">Function index</a></li>
              <li class="defaultLink"><a href="modules.html">Modules</a></li>
              <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li>
              <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li>
              <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li>
            </ul> 
          </div>
        </div>
        <div class="box bottombar" id="topics">
          <h2 title="Qt Topics"><span></span>
            Qt Topics</h2>
          <div id="list002" class="list">
            <ul id="ul002" >
               <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> 
               <li class="defaultLink"><a href="qtquick.html">Device UIs &amp; Qt Quick</a></li> 
               <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> 
               <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li>  
               <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> 
               <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> 
            </ul>  
          </div>
        </div>
        <div class="box" id="examples">
          <h2 title="Examples"><span></span>
            Examples</h2>
          <div id="list003" class="list">
        <ul id="ul003">
              <li class="defaultLink"><a href="all-examples.html">Examples</a></li>
              <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li>
              <li class="defaultLink"><a href="demos.html">Demos</a></li>
              <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li>
            </ul> 
          </div>
        </div>
      </div>
      <div class="wrap">
        <div class="toolbar">
          <div class="breadcrumb toolblock">
            <ul>
              <li class="first"><a href="index.html">Home</a></li>
              <!--  Breadcrumbs go here -->
<li><a href="qdeclarativeelements.html">QML Elements</a></li>
<li>QML Component Element</li>
            </ul>
          </div>
          <div class="toolbuttons toolblock">
            <ul>
              <li id="smallA" class="t_button">A</li>
              <li id="medA" class="t_button active">A</li>
              <li id="bigA" class="t_button">A</li>
              <li id="print" class="t_button"><a href="javascript:this.print();">
                <span>Print</span></a></li>
            </ul>
        </div>
        </div>
        <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="#signal-handlers">Attached Signal Handlers</a></li>
<li class="level1"><a href="#methods">Methods</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<h1 class="title">QML Component Element</h1>
<span class="subtitle"></span>
<!-- $$$Component-brief -->
<p>The Component element encapsulates a QML component definition. <a href="#details">More...</a></p>
<!-- @@@Component -->
<p>Component instantiates the C++ class <a href="qdeclarativecomponent.html">QDeclarativeComponent</a></p>
<p>This element was introduced in Qt 4.7.</p>
<ul>
<li><a href="qml-component-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-component.html#progress-prop">progress</a></b></b> : real</li>
<li class="fn"><b><b><a href="qml-component.html#status-prop">status</a></b></b> : enumeration</li>
<li class="fn"><b><b><a href="qml-component.html#url-prop">url</a></b></b> : url</li>
</ul>
<a name="attached-signal-handlers"></a>
<h2>Attached Signal Handlers</h2>
<ul>
<li class="fn"><b><b><a href="qml-component.html#onCompleted-signal">onCompleted</a></b></b></li>
<li class="fn"><b><b><a href="qml-component.html#onDestruction-signal">onDestruction</a></b></b></li>
</ul>
<a name="methods"></a>
<h2>Methods</h2>
<ul>
<li class="fn"><b><b><a href="qml-component.html#createObject-method">createObject</a></b></b></li>
<li class="fn"><b><b><a href="qml-component.html#errorString-method">errorString</a></b></b></li>
</ul>
<!-- $$$Component-description -->
<a name="details"></a>
<h2>Detailed Description</h2>
<p>Components are reusable, encapsulated QML elements with well-defined interfaces.</p>
<p>Components are often defined by <a href="qdeclarativedocuments.html">component files</a> - that is, <tt>.qml</tt> files. The <i>Component</i> element essentially allows QML components to be defined inline, within a <a href="qdeclarativedocuments.html">QML document</a>, rather than as a separate QML file. This may be useful for reusing a small component within a QML file, or for defining a component that logically belongs with other QML components within a file.</p>
<p>For example, here is a component that is used by multiple <a href="qml-loader.html">Loader</a> objects. It contains a single item, a <a href="qml-rectangle.html">Rectangle</a>:</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">100</span>; <span class="name">height</span>: <span class="number">100</span>

     <span class="type">Component</span> {
         <span class="name">id</span>: <span class="name">redSquare</span>

         <span class="type"><a href="qml-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-loader.html">Loader</a></span> { <span class="name">sourceComponent</span>: <span class="name">redSquare</span> }
     <span class="type"><a href="qml-loader.html">Loader</a></span> { <span class="name">sourceComponent</span>: <span class="name">redSquare</span>; <span class="name">x</span>: <span class="number">20</span> }
 }</pre>
<p>Notice that while a <a href="qml-rectangle.html">Rectangle</a> by itself would be automatically rendered and displayed, this is not the case for the above rectangle because it is defined inside a <tt>Component</tt>. The component encapsulates the QML elements within, as if they were defined in a separate QML file, and is not loaded until requested (in this case, by the two <a href="qml-loader.html">Loader</a> objects).</p>
<p>Defining a <tt>Component</tt> is similar to defining a <a href="qdeclarativedocuments.html">QML document</a>. A QML document has a single top-level item that defines the behaviors and properties of that component, and cannot define properties or behaviors outside of that top-level item. In the same way, a <tt>Component</tt> definition contains a single top level item (which in the above example is a <a href="qml-rectangle.html">Rectangle</a>) and cannot define any data outside of this item, with the exception of an <i>id</i> (which in the above example is <i>redSquare</i>).</p>
<p>The <tt>Component</tt> element is commonly used to provide graphical components for views. For example, the <a href="qml-listview.html#delegate-prop">ListView::delegate</a> property requires a <tt>Component</tt> to specify how each list item is to be displayed.</p>
<p><tt>Component</tt> objects can also be created dynamically using <a href="qml-qt.html#createComponent-method">Qt.createComponent()</a>.</p>
<!-- @@@Component -->
<h2>Property Documentation</h2>
<!-- $$$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="qmlreadonly">read-only</span><span class="name">progress</span> : <span class="type"><a href="qml-real.html">real</a></span></p></td></tr></table></div><div class="qmldoc"><p>The progress of loading the component, from 0.0 (nothing loaded) to 1.0 (finished).</p>
</div></div><!-- @@@progress -->
<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="qmlreadonly">read-only</span><span class="name">status</span> : <span class="type"><a href="qml-enumeration.html">enumeration</a></span></p></td></tr></table></div><div class="qmldoc"><p>This property holds the status of component loading. It can be one of:</p>
<ul>
<li>Component.Null - no data is available for the component</li>
<li>Component.Ready - the component has been loaded, and can be used to create instances.</li>
<li>Component.Loading - the component is currently being loaded</li>
<li>Component.Error - an error occurred while loading the component. Calling <a href="qml-component.html#errorString-method">errorString()</a> will provide a human-readable description of any errors.</li>
</ul>
</div></div><!-- @@@status -->
<br/>
<!-- $$$url -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlPropNode"><p><a name="url-prop"></a><span class="qmlreadonly">read-only</span><span class="name">url</span> : <span class="type"><a href="qml-url.html">url</a></span></p></td></tr></table></div><div class="qmldoc"><p>The component URL. This is the URL that was used to construct the component.</p>
</div></div><!-- @@@url -->
<br/>
<h2>Attached Signal Handler Documentation</h2>
<!-- $$$onCompleted -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlFuncNode"><p><a name="onCompleted-signal"></a>Component::<span class="name">onCompleted</span> ()</p></td></tr></table></div><div class="qmldoc"><p>Emitted after component &quot;startup&quot; has completed. This can be used to execute script code at startup, once the full QML environment has been established.</p>
<p>The <tt>Component::onCompleted</tt> attached property can be applied to any element. The order of running the <tt>onCompleted</tt> scripts is undefined.</p>
<pre class="qml"> <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
     <span class="name">Component</span>.onCompleted: <span class="name">console</span>.<span class="name">log</span>(<span class="string">&quot;Completed Running!&quot;</span>)
     <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
         <span class="name">Component</span>.onCompleted: <span class="name">console</span>.<span class="name">log</span>(<span class="string">&quot;Nested Completed Running!&quot;</span>)
     }
 }</pre>
</div></div><!-- @@@onCompleted -->
<br/>
<!-- $$$onDestruction -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlFuncNode"><p><a name="onDestruction-signal"></a>Component::<span class="name">onDestruction</span> ()</p></td></tr></table></div><div class="qmldoc"><p>Emitted as the component begins destruction. This can be used to undo work done in the <a href="qml-component.html#onCompleted-signal">onCompleted</a> signal, or other imperative code in your application.</p>
<p>The <tt>Component::onDestruction</tt> attached property can be applied to any element. However, it applies to the destruction of the component as a whole, and not the destruction of the specific object. The order of running the <tt>onDestruction</tt> scripts is undefined.</p>
<pre class="qml"> <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
     <span class="name">Component</span>.onDestruction: <span class="name">console</span>.<span class="name">log</span>(<span class="string">&quot;Destruction Beginning!&quot;</span>)
     <span class="type"><a href="qml-rectangle.html">Rectangle</a></span> {
         <span class="name">Component</span>.onDestruction: <span class="name">console</span>.<span class="name">log</span>(<span class="string">&quot;Nested Destruction Beginning!&quot;</span>)
     }
 }</pre>
<p><b>See also </b><a href="qtdeclarative.html">QtDeclarative</a>.</p>
</div></div><!-- @@@onDestruction -->
<br/>
<h2>Method Documentation</h2>
<!-- $$$createObject -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlFuncNode"><p><a name="createObject-method"></a><span class="type">object</span> Component::<span class="name">createObject</span> ( <span class="type"><a href="qml-item.html">Item</a></span> <i>parent</i>, <span class="type">object</span> <i>properties</i> )</p></td></tr></table></div><div class="qmldoc"><p>Creates and returns an object instance of this component that will have the given <i>parent</i> and <i>properties</i>. The <i>properties</i> argument is optional. Returns null if object creation fails.</p>
<p>The object will be created in the same context as the one in which the component was created. This function will always return null when called on components which were not created in QML.</p>
<p>If you wish to create an object without setting a parent, specify <tt>null</tt> for the <i>parent</i> value. Note that if the returned object is to be displayed, you must provide a valid <i>parent</i> value or set the returned object's <a href="qml-item.html#parent-prop">parent</a> property, or else the object will not be visible.</p>
<p>If a <i>parent</i> is not provided to createObject(), a reference to the returned object must be held so that it is not destroyed by the garbage collector. This is true regardless of whether <a href="qml-item.html#parent-prop">Item::parent</a> is set afterwards, since setting the Item parent does not change object ownership; only the graphical parent is changed.</p>
<p>As of QtQuick 1.1, this method accepts an optional <i>properties</i> argument that specifies a map of initial property values for the created object. These values are applied before object creation is finalized. (This is more efficient than setting property values after object creation, particularly where large sets of property values are defined, and also allows property bindings to be set up before the object is created.)</p>
<p>The <i>properties</i> argument is specified as a map of property-value items. For example, the code below creates an object with initial <tt>x</tt> and <tt>y</tt> values of 100 and 200, respectively:</p>
<pre class="js"> var <span class="name">component</span> = <span class="name">Qt</span>.<span class="name">createComponent</span>(<span class="string">&quot;Button.qml&quot;</span>);
 <span class="keyword">if</span> (<span class="name">component</span>.<span class="name">status</span> <span class="operator">==</span> <span class="name">Component</span>.<span class="name">Ready</span>)
     <span class="name">component</span>.<span class="name">createObject</span>(<span class="name">parent</span>, {&quot;x&quot;: <span class="number">100</span>, &quot;y&quot;: 100});</pre>
<p>Dynamically created instances can be deleted with the <tt>destroy()</tt> method. See <a href="qdeclarativedynamicobjects.html">Dynamic Object Management in QML</a> for more information.</p>
</div></div><!-- @@@createObject -->
<br/>
<!-- $$$errorString -->
<div class="qmlitem"><div class="qmlproto"><table class="qmlname"><tr valign="top" class="odd"><td class="tblQmlFuncNode"><p><a name="errorString-method"></a><span class="type"><a href="qml-string.html">string</a></span> Component::<span class="name">errorString</span> ()</p></td></tr></table></div><div class="qmldoc"><p>Returns a human-readable description of any errors.</p>
<p>The string includes the file, location, and description of each error. If multiple errors are present they are separated by a newline character.</p>
<p>If no errors are present, an empty string is returned.</p>
</div></div><!-- @@@errorString -->
<br/>
      </div>
    </div>
    </div> 
    <div class="ft">
      <span></span>
    </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.</p>
    <br />
    <p>
      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.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      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. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
  </div>

  <script src="scripts/functions.js" type="text/javascript"></script>
</body>
</html>