Qt 4.8
|
The QDeclarativeComponent class encapsulates a QML component definition. More...
#include <qdeclarativecomponent.h>
Public Functions | |
qreal | progress () const |
Status | status () const |
QUrl | url () const |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Friends | |
class | QDeclarativeCompositeTypeData |
class | QDeclarativeTypeData |
class | QDeclarativeVME |
enum | Status { Null, Ready, Loading, Error } |
Emitted after component "startup" has completed. More... | |
qreal | progress |
The progress of loading the component, from 0. More... | |
Status | status |
The component's current status. More... | |
QUrl | url |
The component URL. More... | |
QDeclarativeComponent (QObject *parent=0) | |
QDeclarativeComponent (QDeclarativeEngine *, QObject *parent=0) | |
Create a QDeclarativeComponent with no data and give it the specified engine and parent. More... | |
QDeclarativeComponent (QDeclarativeEngine *, const QString &fileName, QObject *parent=0) | |
Create a QDeclarativeComponent from the given fileName and give it the specified parent and engine. More... | |
QDeclarativeComponent (QDeclarativeEngine *, const QUrl &url, QObject *parent=0) | |
Create a QDeclarativeComponent from the given url and give it the specified parent and engine. More... | |
virtual | ~QDeclarativeComponent () |
Destruct the QDeclarativeComponent. More... | |
bool | isNull () const |
Returns true if status() == QDeclarativeComponent::Null. More... | |
bool | isReady () const |
Returns true if status() == QDeclarativeComponent::Ready. More... | |
bool | isError () const |
Returns true if status() == QDeclarativeComponent::Error. More... | |
bool | isLoading () const |
Returns true if status() == QDeclarativeComponent::Loading. More... | |
QList< QDeclarativeError > | errors () const |
Return the list of errors that occurred during the last compile or create operation. More... | |
Q_INVOKABLE QString | errorString () const |
virtual QObject * | create (QDeclarativeContext *context=0) |
Create an object instance from this component. More... | |
virtual QObject * | beginCreate (QDeclarativeContext *) |
This method provides more advanced control over component instance creation. More... | |
virtual void | completeCreate () |
This method provides more advanced control over component instance creation. More... | |
void | loadUrl (const QUrl &url) |
Load the QDeclarativeComponent from the provided url. More... | |
void | setData (const QByteArray &, const QUrl &baseUrl) |
Sets the QDeclarativeComponent to use the given QML data. More... | |
QDeclarativeContext * | creationContext () const |
Returns the QDeclarativeContext the component was created in. More... | |
static QDeclarativeComponentAttached * | qmlAttachedProperties (QObject *) |
void | statusChanged (QDeclarativeComponent::Status) |
Emitted whenever the component's status changes. More... | |
void | progressChanged (qreal) |
Emitted whenever the component's loading progress changes. More... | |
QDeclarativeComponent (QDeclarativeComponentPrivate &dd, QObject *parent) | |
Q_INVOKABLE QScriptValue | createObject (QObject *parent) |
A version of create which returns a scriptObject, for use in script. More... | |
Q_INVOKABLE QScriptValue | createObject (QObject *parent, const QScriptValue &valuemap) |
QDeclarativeComponent (QDeclarativeEngine *, QDeclarativeCompiledData *, int, int, QObject *parent) | |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
The 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 QDeclarativeComponent instance can be created from a QML file. For example, if there is a main.qml
file like this:
The following code loads this QML file as a component, creates an instance of this component using create(), and then queries the Item's Item::width value:
If the URL passed to QDeclarativeComponent is a network resource, or if the QML document references a network resource, the QDeclarativeComponent has to fetch the network data before it is able to create objects. In this case, the QDeclarativeComponent will have a QDeclarativeComponent::Loading{Loading} QDeclarativeComponent::status(){status}. An application will have to wait until the component is QDeclarativeComponent::Ready{Ready} before calling QDeclarativeComponent::create().
The following example shows how to load a QML file from a network resource. After creating the 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.
Definition at line 63 of file qdeclarativecomponent.h.
Emitted after component "startup" has completed.
Component::onCompleted()
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.
Emitted as the component begins destruction.
Component::onDestruction()
This can be used to undo work done in the onCompleted signal, or other imperative code in your application.
The {Component::onDestruction}
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 onDestruction
scripts is undefined.
Specifies the loading status of the QDeclarativeComponent.
Enumerator | |
---|---|
Null | |
Ready | |
Loading | |
Error |
Definition at line 80 of file qdeclarativecomponent.h.
QDeclarativeComponent::QDeclarativeComponent | ( | QObject * | parent = 0 | ) |
Definition at line 309 of file qdeclarativecomponent.cpp.
QDeclarativeComponent::QDeclarativeComponent | ( | QDeclarativeEngine * | engine, |
QObject * | parent = 0 |
||
) |
Create a QDeclarativeComponent with no data and give it the specified engine and parent.
Set the data with setData().
Definition at line 449 of file qdeclarativecomponent.cpp.
QDeclarativeComponent::QDeclarativeComponent | ( | QDeclarativeEngine * | engine, |
const QString & | fileName, | ||
QObject * | parent = 0 |
||
) |
Create a QDeclarativeComponent from the given fileName and give it the specified parent and engine.
Definition at line 479 of file qdeclarativecomponent.cpp.
QDeclarativeComponent::QDeclarativeComponent | ( | QDeclarativeEngine * | engine, |
const QUrl & | url, | ||
QObject * | parent = 0 |
||
) |
Create a QDeclarativeComponent from the given url and give it the specified parent and engine.
Ensure that the URL provided is full and correct, in particular, use QUrl::fromLocalFile() when loading a file from the local filesystem.
Definition at line 465 of file qdeclarativecomponent.cpp.
|
virtual |
Destruct the QDeclarativeComponent.
Definition at line 317 of file qdeclarativecomponent.cpp.
|
protected |
Definition at line 654 of file qdeclarativecomponent.cpp.
|
private |
Definition at line 491 of file qdeclarativecomponent.cpp.
|
virtual |
This method provides more advanced control over component instance creation.
In general, programmers should use QDeclarativeComponent::create() to create a component.
Create an object instance from this component. Returns 0 if creation failed. context specifies the context within which to create the object instance.
When QDeclarativeComponent constructs an instance, it occurs in three steps:
QDeclarativeComponent::beginCreate() differs from QDeclarativeComponent::create() in that it only performs step 1. QDeclarativeComponent::completeCreate() must be called to complete steps 2 and 3.
This breaking point is sometimes useful when using attached properties to communicate information to an instantiated component, as it allows their initial values to be configured before property bindings take effect.
Definition at line 843 of file qdeclarativecomponent.cpp.
Referenced by create(), and QDeclarativeEnginePrivate::createQmlObject().
|
virtual |
This method provides more advanced control over component instance creation.
In general, programmers should use QDeclarativeComponent::create() to create a component.
Complete a component creation begin with QDeclarativeComponent::beginCreate().
Definition at line 1081 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeLoaderPrivate::_q_sourceLoaded(), create(), and QDeclarativeEnginePrivate::createQmlObject().
|
virtual |
Create an object instance from this component.
Returns 0 if creation failed. context specifies the context within which to create the object instance.
If context is 0 (the default), it will create the instance in the engine' s QDeclarativeEngine::rootContext(){root context}.
Definition at line 808 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeGridViewPrivate::createComponentItem(), QDeclarativeListViewPrivate::createComponentItem(), and QmlJSDebugger::AbstractViewInspector::createQmlObject().
|
protected |
A version of create which returns a scriptObject, for use in script.
This function will only work on components created in QML.
Sets graphics object parent because forgetting to do this is a frequent and serious problem.
Definition at line 712 of file qdeclarativecomponent.cpp.
|
protected |
Definition at line 722 of file qdeclarativecomponent.cpp.
QDeclarativeContext * QDeclarativeComponent::creationContext | ( | ) | const |
Returns the QDeclarativeContext the component was created in.
This is only valid for components created directly from QML.
Definition at line 535 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeComponentPrivate::beginCreate(), QDeclarativeGridViewPrivate::createComponentItem(), and QDeclarativeListViewPrivate::createComponentItem().
QList< QDeclarativeError > QDeclarativeComponent::errors | ( | ) | const |
Return the list of errors that occurred during the last compile or create operation.
An empty list is returned if isError() is not set.
Definition at line 588 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeEnginePrivate::createQmlObject().
QString QDeclarativeComponent::errorString | ( | ) | const |
Definition at line 615 of file qdeclarativecomponent.cpp.
bool QDeclarativeComponent::isError | ( | ) | const |
Returns true if status() == QDeclarativeComponent::Error.
Definition at line 389 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeEnginePrivate::createQmlObject(), errors(), and errorString().
bool QDeclarativeComponent::isLoading | ( | ) | const |
Returns true if status() == QDeclarativeComponent::Loading.
Definition at line 397 of file qdeclarativecomponent.cpp.
bool QDeclarativeComponent::isNull | ( | ) | const |
Returns true if status() == QDeclarativeComponent::Null.
Definition at line 373 of file qdeclarativecomponent.cpp.
bool QDeclarativeComponent::isReady | ( | ) | const |
Returns true if status() == QDeclarativeComponent::Ready.
Definition at line 381 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeEnginePrivate::createQmlObject(), and QDeclarativeTextEdit::setCursorDelegate().
void QDeclarativeComponent::loadUrl | ( | const QUrl & | url | ) |
Load the QDeclarativeComponent from the provided url.
Ensure that the URL provided is full and correct, in particular, use QUrl::fromLocalFile() when loading a file from the local filesystem.
Definition at line 550 of file qdeclarativecomponent.cpp.
Referenced by QDeclarativeComponent().
qreal QDeclarativeComponent::progress | ( | ) | const |
Referenced by isLoading().
|
signal |
|
static |
Definition at line 1113 of file qdeclarativecomponent.cpp.
void QDeclarativeComponent::setData | ( | const QByteArray & | data, |
const QUrl & | url | ||
) |
Sets the QDeclarativeComponent to use the given QML data.
If url is provided, it is used to set the component name and to provide a base path for items resolved by this component.
Definition at line 509 of file qdeclarativecomponent.cpp.
Referenced by QmlJSDebugger::AbstractViewInspector::createQmlObject(), and QDeclarativeEnginePrivate::createQmlObject().
Status QDeclarativeComponent::status | ( | ) | const |
Referenced by QDeclarativeComponentPrivate::complete(), isError(), isLoading(), isNull(), isReady(), loadUrl(), setData(), and ~QDeclarativeComponent().
|
signal |
QUrl QDeclarativeComponent::url | ( | ) | const |
Referenced by errorString(), loadUrl(), and setData().
|
friend |
Definition at line 120 of file qdeclarativecomponent.h.
|
friend |
Definition at line 121 of file qdeclarativecomponent.h.
|
friend |
Definition at line 119 of file qdeclarativecomponent.h.
|
private |
The progress of loading the component, from 0.
0 (nothing loaded) to 1.0 (finished).
Definition at line 68 of file qdeclarativecomponent.h.
|
private |
The component's current status.
Definition at line 69 of file qdeclarativecomponent.h.
|
private |
The component URL.
This is the URL passed to either the constructor, or the loadUrl() or setData() methods.
Definition at line 70 of file qdeclarativecomponent.h.