Home · All Classes · All Functions · Overviews

QML Component Element Reference

[Component instantiates the C++ class QDeclarativeComponent]

The Component element encapsulates a QML component description. More...

Detailed Description

Components are reusable, encapsulated Qml element with a well-defined interface. They are often defined in Component Files.

The Component element allows defining components within a QML file. This can be useful for reusing a small component within a single QML file, or for defining a component that logically belongs with the file containing it.

 Item {
     Component {
         id: redSquare
         Rectangle {
             color: "red"
             width: 10
             height: 10
         }
     }
     Loader { sourceComponent: redSquare }
     Loader { sourceComponent: redSquare; x: 20 }
 }

Attached Properties

onCompleted

Emitted after component "startup" has completed. This can be used to execute script code at startup, once the full QML environment has been established.

The Component::onCompleted attached property can be applied to any element. The order of running the onCompleted scripts is undefined.

     Rectangle {
         Component.onCompleted: console.log("Completed Running!")
         Rectangle {
             Component.onCompleted: console.log("Nested Completed Running!")
         }
     }


Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt 4.7.0