Home · All Classes · All Functions · Overviews

QML Loader Element Reference

[Inherits Item]

The Loader item allows dynamically loading an Item-based subtree from a QML URL or Component. More...

Properties

Detailed Description

Loader instantiates an item from a component. The component to instantiate may be specified directly by the sourceComponent property, or loaded from a URL via the source property.

It is also an effective means of delaying the creation of a component until it is required:

 Loader { id: pageLoader }
 Rectangle {
     MouseArea { anchors.fill: parent; onClicked: pageLoader.source = "Page1.qml" }
 }

If the Loader source is changed, any previous items instantiated will be destroyed. Setting source to an empty string will destroy the currently instantiated items, freeing resources and leaving the Loader empty. For example:

 pageLoader.source = ""

unloads "Page1.qml" and frees resources consumed by it.

See also Dynamic Object Creation.


Property Documentation

read-onlyitem : Item

This property holds the top-level item created from source.


read-onlyprogress : real

This property holds the progress of QML data loading, from 0.0 (nothing loaded) to 1.0 (finished).

See also status.


resizeMode : enum

This property determines how the Loader or item are resized:

Note that changing from SizeItemToLoader to SizeLoaderToItem after the component is loaded will not return the item or Loader to it's original size. This is due to the item size being adjusted to the Loader size, thereby losing the original size of the item. Future changes to the item's size will affect the loader, however.

The default resizeMode is SizeLoaderToItem.


source : url

This property holds the URL of the QML component to instantiate.

See also sourceComponent, status, and progress.


sourceComponent : Component

The sourceComponent property holds the Component to instantiate.

 Item {
     Component {
         id: redSquare
         Rectangle { color: "red"; width: 10; height: 10 }
     }

     Loader { sourceComponent: redSquare }
     Loader { sourceComponent: redSquare; x: 10 }
 }

See also source and progress.


read-onlystatus : enum

This property holds the status of QML loading. It can be one of:

See also progress.



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