diff options
Diffstat (limited to 'src/declarative/qml/qmlcomponent.cpp')
-rw-r--r-- | src/declarative/qml/qmlcomponent.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlcomponent.cpp b/src/declarative/qml/qmlcomponent.cpp index 65af9a5..63f3cfb 100644 --- a/src/declarative/qml/qmlcomponent.cpp +++ b/src/declarative/qml/qmlcomponent.cpp @@ -409,6 +409,9 @@ valid for components created directly from QML. */ QmlContext *QmlComponent::creationContext() const { + Q_D(const QmlComponent); + if(d->creationContext) + return d->creationContext; QmlDeclarativeData *ddata = QmlDeclarativeData::get(this); if (ddata) return ddata->context; @@ -417,6 +420,17 @@ QmlContext *QmlComponent::creationContext() const } /*! + \internal + Sets the QmlContext the component was created in. This is only + desirable for components created in QML script. +*/ +void QmlComponent::setCreationContext(QmlContext* c) +{ + Q_D(QmlComponent); + d->creationContext = c; +} + +/*! Load the QmlComponent from the provided \a url. */ void QmlComponent::loadUrl(const QUrl &url) @@ -462,6 +476,24 @@ QList<QmlError> QmlComponent::errors() const } /*! + \internal + errorsString is only meant as a way to get the errors in script +*/ +QString QmlComponent::errorsString() const +{ + Q_D(const QmlComponent); + QString ret; + if(!isError()) + return ret; + foreach(const QmlError &e, d->errors) { + ret += e.url().toString() + QLatin1String(":") + + QString::number(e.line()) + QLatin1String(" ") + + e.description() + QLatin1String("\n"); + } + return ret; +} + +/*! Return the component URL. This is the URL passed to either the constructor, or the loadUrl() or setData() methods. */ @@ -481,6 +513,22 @@ QmlComponent::QmlComponent(QmlComponentPrivate &dd, QObject *parent) /*! + \internal + A version of create which returns a scriptObject, for use in script +*/ +QScriptValue QmlComponent::createObject() +{ + Q_D(QmlComponent); + QmlContext* ctxt = creationContext(); + if(!ctxt){ + qWarning() << QLatin1String("createObject can only be used in QML"); + return QScriptValue(); + } + QObject* ret = create(ctxt); + return QmlEnginePrivate::qmlScriptObject(ret, d->engine); +} + +/*! Create an object instance from this component. Returns 0 if creation failed. \a context specifies the context within which to create the object instance. |