QDeclarativeComponent

Inheritance diagram of QDeclarativeComponent

Synopsis

Functions

Virtual functions

Signals

Detailed Description

The PySide.QtDeclarative.QDeclarativeComponent class encapsulates a QML component definition.

Components are reusable, encapsulated QML elements with well-defined interfaces. They are often defined in Component Files .

A PySide.QtDeclarative.QDeclarativeComponent instance can be created from a QML file. For example, if there is a main.qml file like this:

import QtQuick 1.0

Item {
    width: 200
    height: 200
}

The following code loads this QML file as a component, creates an instance of this component using PySide.QtDeclarative.QDeclarativeComponent.create() , and then queries the Item ‘s width value:

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();  // width = 200

Network Components

If the URL passed to PySide.QtDeclarative.QDeclarativeComponent is a network resource, or if the QML document references a network resource, the PySide.QtDeclarative.QDeclarativeComponent has to fetch the network data before it is able to create objects. In this case, the PySide.QtDeclarative.QDeclarativeComponent will have a Loading PySide.QtDeclarative.QDeclarativeComponent.status() . An application will have to wait until the component is Ready before calling QDeclarativeComponent.create() .

The following example shows how to load a QML file from a network resource. After creating the PySide.QtDeclarative.QDeclarativeComponent , it tests whether the component is loading. If it is, it connects to the QDeclarativeComponent.statusChanged() signal and otherwise calls the continueLoading() method directly. Note that QDeclarativeComponent.isLoading() may be false for a network component if the component has been cached and is ready immediately.

MyApplication::MyApplication()
{
    // ...
    component = new QDeclarativeComponent(engine, QUrl("http://www.example.com/main.qml"));
    if (component->isLoading())
        QObject::connect(component, SIGNAL(statusChanged(QDeclarativeComponent::Status)),
                         this, SLOT(continueLoading()));
    else
        continueLoading();
}

void MyApplication::continueLoading()
{
    if (component->isError()) {
        qWarning() << component->errors();
    } else {
        QObject *myObject = component->create();
    }
}
class PySide.QtDeclarative.QDeclarativeComponent(arg__1[, parent=None])
class PySide.QtDeclarative.QDeclarativeComponent(arg__1, fileName[, parent=None])
class PySide.QtDeclarative.QDeclarativeComponent(arg__1, url[, parent=None])
Parameters:
PySide.QtDeclarative.QDeclarativeComponent.Status
PySide.QtDeclarative.QDeclarativeComponent.beginCreate(arg__1)
Parameters:arg__1PySide.QtDeclarative.QDeclarativeContext
Return type:PySide.QtCore.QObject
PySide.QtDeclarative.QDeclarativeComponent.completeCreate()
PySide.QtDeclarative.QDeclarativeComponent.create([context=None])
Parameters:contextPySide.QtDeclarative.QDeclarativeContext
Return type:PySide.QtCore.QObject
PySide.QtDeclarative.QDeclarativeComponent.createObject(parent, valuemap)
Parameters:
Return type:

PySide.QtScript.QScriptValue

PySide.QtDeclarative.QDeclarativeComponent.createObject(parent)
Parameters:parentPySide.QtCore.QObject
Return type:PySide.QtScript.QScriptValue
PySide.QtDeclarative.QDeclarativeComponent.creationContext()
Return type:PySide.QtDeclarative.QDeclarativeContext
PySide.QtDeclarative.QDeclarativeComponent.errorString()
Return type:unicode
PySide.QtDeclarative.QDeclarativeComponent.errors()
Return type:
PySide.QtDeclarative.QDeclarativeComponent.isError()
Return type:PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent.isLoading()
Return type:PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent.isNull()
Return type:PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent.isReady()
Return type:PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent.loadUrl(url)
Parameters:urlPySide.QtCore.QUrl
PySide.QtDeclarative.QDeclarativeComponent.progress()
Return type:PySide.QtCore.qreal
PySide.QtDeclarative.QDeclarativeComponent.progressChanged(arg__1)
Parameters:arg__1PySide.QtCore.qreal
PySide.QtDeclarative.QDeclarativeComponent.setData(arg__1, baseUrl)
Parameters:
PySide.QtDeclarative.QDeclarativeComponent.status()
Return type:PySide.QtDeclarative.QDeclarativeComponent.Status
PySide.QtDeclarative.QDeclarativeComponent.statusChanged(arg__1)
Parameters:arg__1PySide.QtDeclarative.QDeclarativeComponent.Status
PySide.QtDeclarative.QDeclarativeComponent.url()
Return type:PySide.QtCore.QUrl