QDeclarativeComponent

概要

函数

虚函数

信号

详细描述

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 ] )
参数:
PySide.QtDeclarative.QDeclarativeComponent. 状态
PySide.QtDeclarative.QDeclarativeComponent. beginCreate ( arg__1 )
参数: arg__1 PySide.QtDeclarative.QDeclarativeContext
返回类型: PySide.QtCore.QObject
PySide.QtDeclarative.QDeclarativeComponent. completeCreate ( )
PySide.QtDeclarative.QDeclarativeComponent. create ( [ context=None ] )
参数: context PySide.QtDeclarative.QDeclarativeContext
返回类型: PySide.QtCore.QObject
PySide.QtDeclarative.QDeclarativeComponent. createObject ( parent , valuemap )
参数:
返回类型:

PySide.QtScript.QScriptValue

PySide.QtDeclarative.QDeclarativeComponent. createObject ( parent )
参数: parent PySide.QtCore.QObject
返回类型: PySide.QtScript.QScriptValue
PySide.QtDeclarative.QDeclarativeComponent. creationContext ( )
返回类型: PySide.QtDeclarative.QDeclarativeContext
PySide.QtDeclarative.QDeclarativeComponent. errorString ( )
返回类型: unicode
PySide.QtDeclarative.QDeclarativeComponent. errors ( )
返回类型:
PySide.QtDeclarative.QDeclarativeComponent. isError ( )
返回类型: PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent. isLoading ( )
返回类型: PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent. isNull ( )
返回类型: PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent. isReady ( )
返回类型: PySide.QtCore.bool
PySide.QtDeclarative.QDeclarativeComponent. loadUrl ( url )
参数: url PySide.QtCore.QUrl
PySide.QtDeclarative.QDeclarativeComponent. progress ( )
返回类型: PySide.QtCore.qreal
PySide.QtDeclarative.QDeclarativeComponent. progressChanged ( arg__1 )
参数: arg__1 PySide.QtCore.qreal
PySide.QtDeclarative.QDeclarativeComponent. setData ( arg__1 , baseUrl )
参数:
PySide.QtDeclarative.QDeclarativeComponent. status ( )
返回类型: PySide.QtDeclarative.QDeclarativeComponent.Status
PySide.QtDeclarative.QDeclarativeComponent. statusChanged ( arg__1 )
参数: arg__1 PySide.QtDeclarative.QDeclarativeComponent.Status
PySide.QtDeclarative.QDeclarativeComponent. url ( )
返回类型: PySide.QtCore.QUrl