Qt 4.8
Public Functions | Friends | List of all members
QDeclarativeComponent Class Reference

The QDeclarativeComponent class encapsulates a QML component definition. More...

#include <qdeclarativecomponent.h>

Inheritance diagram for QDeclarativeComponent:
QObject

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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () 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 >
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 QMetaObjectmetaObject () 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
 
QObjectparent () 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...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (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< QDeclarativeErrorerrors () const
 Return the list of errors that occurred during the last compile or create operation. More...
 
Q_INVOKABLE QString errorString () const
 
virtual QObjectcreate (QDeclarativeContext *context=0)
 Create an object instance from this component. More...
 
virtual QObjectbeginCreate (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...
 
QDeclarativeContextcreationContext () const
 Returns the QDeclarativeContext the component was created in. More...
 
static QDeclarativeComponentAttachedqmlAttachedProperties (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...
 
QObjectsender () 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< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QDeclarativeComponent class encapsulates a QML component definition.

Since
4.7

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:

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 create(), and then queries the Item's Item::width value:

QObject *myObject = component.create();
int width = item->width(); // width = 200

Network Components

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.

MyApplication::MyApplication()
{
// ...
component = new QDeclarativeComponent(engine, QUrl("http://www.example.com/main.qml"));
if (component->isLoading())
this, SLOT(continueLoading()));
else
continueLoading();
}
void MyApplication::continueLoading()
{
if (component->isError()) {
qWarning() << component->errors();
} else {
QObject *myObject = component->create();
}
}
See also
{Using QML Bindings in C++ Applications}, {Integrating QML Code with Existing Qt UI Code}

Definition at line 63 of file qdeclarativecomponent.h.

Enumerations

◆ Status

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.

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

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.

Component.onDestruction: console.log("Destruction Beginning!")
Component.onDestruction: console.log("Nested Destruction Beginning!")
}
}
See also
QtDeclarative

Specifies the loading status of the QDeclarativeComponent.

Enumerator
Null 
Ready 
Loading 
Error 

Definition at line 80 of file qdeclarativecomponent.h.

Constructors and Destructors

◆ QDeclarativeComponent() [1/6]

QDeclarativeComponent::QDeclarativeComponent ( QObject parent = 0)
Warning
This function is not part of the public interface.

Definition at line 309 of file qdeclarativecomponent.cpp.

310  : QObject(*(new QDeclarativeComponentPrivate), parent)
311 {
312 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QDeclarativeComponent() [2/6]

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.

450  : QObject(*(new QDeclarativeComponentPrivate), parent)
451 {
453  d->engine = engine;
454 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QDeclarativeComponent() [3/6]

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.

See also
loadUrl()

Definition at line 479 of file qdeclarativecomponent.cpp.

481 : QObject(*(new QDeclarativeComponentPrivate), parent)
482 {
484  d->engine = engine;
485  loadUrl(d->engine->baseUrl().resolved(QUrl::fromLocalFile(fileName)));
486 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void loadUrl(const QUrl &url)
Load the QDeclarativeComponent from the provided url.
The QDeclarativeComponent class encapsulates a QML component definition.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374

◆ QDeclarativeComponent() [4/6]

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.

See also
loadUrl()

Definition at line 465 of file qdeclarativecomponent.cpp.

466 : QObject(*(new QDeclarativeComponentPrivate), parent)
467 {
469  d->engine = engine;
470  loadUrl(url);
471 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
void loadUrl(const QUrl &url)
Load the QDeclarativeComponent from the provided url.
The QDeclarativeComponent class encapsulates a QML component definition.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QDeclarativeComponent()

QDeclarativeComponent::~QDeclarativeComponent ( )
virtual

Destruct the QDeclarativeComponent.

Definition at line 317 of file qdeclarativecomponent.cpp.

318 {
320 
321  if (d->state.completePending) {
322  qWarning("QDeclarativeComponent: Component destroyed while completion pending");
323  d->completeCreate();
324  }
325 
326  if (d->typeData) {
327  d->typeData->unregisterCallback(d);
328  d->typeData->release();
329  }
330  if (d->cc)
331  d->cc->release();
332 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
Q_CORE_EXPORT void qWarning(const char *,...)

◆ QDeclarativeComponent() [5/6]

QDeclarativeComponent::QDeclarativeComponent ( QDeclarativeComponentPrivate dd,
QObject parent 
)
protected
Warning
This function is not part of the public interface.

Definition at line 654 of file qdeclarativecomponent.cpp.

655  : QObject(dd, parent)
656 {
657 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QDeclarativeComponent() [6/6]

QDeclarativeComponent::QDeclarativeComponent ( QDeclarativeEngine engine,
QDeclarativeCompiledData cc,
int  start,
int  count,
QObject parent 
)
private
Warning
This function is not part of the public interface.

Definition at line 491 of file qdeclarativecomponent.cpp.

492  : QObject(*(new QDeclarativeComponentPrivate), parent)
493 {
495  d->engine = engine;
496  d->cc = cc;
497  cc->addref();
498  d->start = start;
499  d->count = count;
500  d->url = cc->url;
501  d->progress = 1.0;
502 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

Functions

◆ beginCreate()

QObject * QDeclarativeComponent::beginCreate ( QDeclarativeContext context)
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:

  1. The object hierarchy is created, and constant values are assigned.
  2. Property bindings are evaluated for the the first time.
  3. If applicable, QDeclarativeParserStatus::componentComplete() is called on objects.

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().

844 {
846  QObject *rv = d->beginCreate(context?QDeclarativeContextData::get(context):0, QBitField());
847  if (rv) {
849  Q_ASSERT(ddata);
850  ddata->indestructible = true;
851  }
852  return rv;
853 }
double d
Definition: qnumeric_p.h:62
static QDeclarativeData * get(const QObject *object, bool create=false)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
static QDeclarativeContextData * get(QDeclarativeContext *context)

◆ completeCreate()

void QDeclarativeComponent::completeCreate ( )
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().

1082 {
1084  d->completeCreate();
1085 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.

◆ create()

QObject * QDeclarativeComponent::create ( QDeclarativeContext context = 0)
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().

809 {
811 
812  if (!context)
813  context = d->engine->rootContext();
814 
815  QObject *rv = beginCreate(context);
816  completeCreate();
817  return rv;
818 }
double d
Definition: qnumeric_p.h:62
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
virtual QObject * beginCreate(QDeclarativeContext *)
This method provides more advanced control over component instance creation.
virtual void completeCreate()
This method provides more advanced control over component instance creation.

◆ createObject() [1/2]

QScriptValue QDeclarativeComponent::createObject ( QObject parent)
protected

A version of create which returns a scriptObject, for use in script.

Warning
This function is not part of the public interface.

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.

713 {
715  return d->createObject(parent, QScriptValue(QScriptValue::NullValue));
716 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ createObject() [2/2]

QScriptValue QDeclarativeComponent::createObject ( QObject parent,
const QScriptValue valuemap 
)
protected
Warning
This function is not part of the public interface. Overloadable method allows properties to be set during creation

Definition at line 722 of file qdeclarativecomponent.cpp.

723 {
725 
726  if (!valuemap.isObject() || valuemap.isArray()) {
727  qmlInfo(this) << tr("createObject: value is not an object");
729  }
730  return d->createObject(parent, valuemap);
731 }
double d
Definition: qnumeric_p.h:62
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
bool isArray() const
Returns true if this QScriptValue is an object of the Array class; otherwise returns false...
QDeclarativeInfo qmlInfo(const QObject *me)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
bool isObject() const
Returns true if this QScriptValue is of the Object type; otherwise returns false. ...

◆ creationContext()

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().

536 {
537  Q_D(const QDeclarativeComponent);
538  if(d->creationContext)
539  return d->creationContext->asQDeclarativeContext();
540 
541  return qmlContext(this);
542 }
double d
Definition: qnumeric_p.h:62
Q_DECLARATIVE_EXPORT QDeclarativeContext * qmlContext(const QObject *)
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.

◆ errors()

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().

589 {
590  Q_D(const QDeclarativeComponent);
591  if (isError())
592  return d->state.errors;
593  else
594  return QList<QDeclarativeError>();
595 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
bool isError() const
Returns true if status() == QDeclarativeComponent::Error.

◆ errorString()

QString QDeclarativeComponent::errorString ( ) const
Warning
This function is not part of the public interface. errorString is only meant as a way to get the errors in script

Definition at line 615 of file qdeclarativecomponent.cpp.

616 {
617  Q_D(const QDeclarativeComponent);
618  QString ret;
619  if(!isError())
620  return ret;
621  foreach(const QDeclarativeError &e, d->state.errors) {
622  ret += e.url().toString() + QLatin1Char(':') +
623  QString::number(e.line()) + QLatin1Char(' ') +
624  e.description() + QLatin1Char('\n');
625  }
626  return ret;
627 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
double d
Definition: qnumeric_p.h:62
QUrl url() const
Returns the url for the file that caused this error.
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeComponent class encapsulates a QML component definition.
QString description() const
Returns the error description.
The QDeclarativeError class encapsulates a QML error.
int line() const
Returns the error line number.
bool isError() const
Returns true if status() == QDeclarativeComponent::Error.
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ isError()

bool QDeclarativeComponent::isError ( ) const

◆ isLoading()

bool QDeclarativeComponent::isLoading ( ) const

Returns true if status() == QDeclarativeComponent::Loading.

Definition at line 397 of file qdeclarativecomponent.cpp.

398 {
399  return status() == Loading;
400 }
Status status() const

◆ isNull()

bool QDeclarativeComponent::isNull ( ) const

Returns true if status() == QDeclarativeComponent::Null.

Definition at line 373 of file qdeclarativecomponent.cpp.

374 {
375  return status() == Null;
376 }
Status status() const

◆ isReady()

bool QDeclarativeComponent::isReady ( ) const

◆ loadUrl()

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().

551 {
553 
554  d->clear();
555 
556  if ((url.isRelative() && !url.isEmpty())
557  || url.scheme() == QLatin1String("file")) // Workaround QTBUG-11929
558  d->url = d->engine->baseUrl().resolved(url);
559  else
560  d->url = url;
561 
562  if (url.isEmpty()) {
564  error.setDescription(tr("Invalid empty URL"));
565  d->state.errors << error;
566  return;
567  }
568 
570 
571  if (data->isCompleteOrError()) {
572  d->fromTypeData(data);
573  d->progress = 1.0;
574  } else {
575  d->typeData = data;
576  d->typeData->registerCallback(d);
577  d->progress = data->progress();
578  }
579 
581  emit progressChanged(d->progress);
582 }
double d
Definition: qnumeric_p.h:62
void setDescription(const QString &)
Sets the error description.
#define error(msg)
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
bool isCompleteOrError() const
Returns true if the status is Complete or Error.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QDeclarativeTypeLoader typeLoader
#define Q_D(Class)
Definition: qglobal.h:2482
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
Definition: qurl.cpp:5880
qreal progress() const
Returns the data download progress from 0 to 1.
The QDeclarativeComponent class encapsulates a QML component definition.
#define emit
Definition: qobjectdefs.h:76
static const char * data(const QByteArray &arr)
The QDeclarativeError class encapsulates a QML error.
Status status() const
QString scheme() const
Returns the scheme of the URL.
Definition: qurl.cpp:4550
QDeclarativeTypeData * get(const QUrl &url)
Returns a QDeclarativeTypeData for the specified url.
void statusChanged(QDeclarativeComponent::Status)
Emitted whenever the component&#39;s status changes.
void progressChanged(qreal)
Emitted whenever the component&#39;s loading progress changes.

◆ progress()

qreal QDeclarativeComponent::progress ( ) const

Referenced by isLoading().

◆ progressChanged

void QDeclarativeComponent::progressChanged ( qreal  progress)
signal

Emitted whenever the component's loading progress changes.

progress will be the current progress between 0.0 (nothing loaded) and 1.0 (finished).

Referenced by loadUrl(), and setData().

◆ qmlAttachedProperties()

QDeclarativeComponentAttached * QDeclarativeComponent::qmlAttachedProperties ( QObject obj)
static
Warning
This function is not part of the public interface.

Definition at line 1113 of file qdeclarativecomponent.cpp.

1114 {
1116 
1117  QDeclarativeEngine *engine = qmlEngine(obj);
1118  if (!engine)
1119  return a;
1120 
1121  if (QDeclarativeEnginePrivate::get(engine)->inBeginCreate) {
1123  a->add(&p->componentAttached);
1124  } else {
1126  Q_ASSERT(d);
1127  Q_ASSERT(d->context);
1128  a->add(&d->context->componentAttached);
1129  }
1130 
1131  return a;
1132 }
double d
Definition: qnumeric_p.h:62
QDeclarativeContextData * context
static QDeclarativeData * get(const QObject *object, bool create=false)
QDeclarativeComponentAttached * componentAttached
void add(QDeclarativeComponentAttached **a)
long ASN1_INTEGER_get ASN1_INTEGER * a
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
Q_DECLARATIVE_EXPORT QDeclarativeEngine * qmlEngine(const QObject *)
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativeComponentAttached * componentAttached

◆ setData()

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().

510 {
512 
513  d->clear();
514 
515  d->url = url;
516 
517  QDeclarativeTypeData *typeData = QDeclarativeEnginePrivate::get(d->engine)->typeLoader.get(data, url);
518 
519  if (typeData->isCompleteOrError()) {
520  d->fromTypeData(typeData);
521  } else {
522  d->typeData = typeData;
523  d->typeData->registerCallback(d);
524  }
525 
526  d->progress = 1.0;
528  emit progressChanged(d->progress);
529 }
double d
Definition: qnumeric_p.h:62
bool isCompleteOrError() const
Returns true if the status is Complete or Error.
QDeclarativeTypeLoader typeLoader
#define Q_D(Class)
Definition: qglobal.h:2482
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
The QDeclarativeComponent class encapsulates a QML component definition.
#define emit
Definition: qobjectdefs.h:76
Status status() const
QDeclarativeTypeData * get(const QUrl &url)
Returns a QDeclarativeTypeData for the specified url.
void statusChanged(QDeclarativeComponent::Status)
Emitted whenever the component&#39;s status changes.
void progressChanged(qreal)
Emitted whenever the component&#39;s loading progress changes.

◆ status()

Status QDeclarativeComponent::status ( ) const

◆ statusChanged

void QDeclarativeComponent::statusChanged ( QDeclarativeComponent::Status  status)
signal

Emitted whenever the component's status changes.

status will be the new status.

Referenced by loadUrl(), and setData().

◆ url()

QUrl QDeclarativeComponent::url ( ) const

Referenced by errorString(), loadUrl(), and setData().

Friends and Related Functions

◆ QDeclarativeCompositeTypeData

friend class QDeclarativeCompositeTypeData
friend

Definition at line 120 of file qdeclarativecomponent.h.

◆ QDeclarativeTypeData

friend class QDeclarativeTypeData
friend

Definition at line 121 of file qdeclarativecomponent.h.

◆ QDeclarativeVME

friend class QDeclarativeVME
friend

Definition at line 119 of file qdeclarativecomponent.h.

Properties

◆ progress

qreal QDeclarativeComponent::progress
private

The progress of loading the component, from 0.

0 (nothing loaded) to 1.0 (finished).

Definition at line 68 of file qdeclarativecomponent.h.

◆ status

QDeclarativeComponent::Status QDeclarativeComponent::status
private

The component's current status.

Definition at line 69 of file qdeclarativecomponent.h.

◆ url

QUrl QDeclarativeComponent::url
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.


The documentation for this class was generated from the following files: