diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2010-04-21 07:24:41 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2010-04-21 07:24:41 (GMT) |
commit | 550f7a2aadbd46c7bd6f30e1faa0bb9a1241a3cf (patch) | |
tree | 6096fb849261ad6328721a97cc06c4630d675040 /src | |
parent | cffe02d1c7aa5f087558fcbabdab890b979ae5cc (diff) | |
parent | e39958e76340698cc2b0ac88a03167a016b9c07b (diff) | |
download | Qt-550f7a2aadbd46c7bd6f30e1faa0bb9a1241a3cf.zip Qt-550f7a2aadbd46c7bd6f30e1faa0bb9a1241a3cf.tar.gz Qt-550f7a2aadbd46c7bd6f30e1faa0bb9a1241a3cf.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/QmlChanges.txt | 2 | ||||
-rw-r--r-- | src/declarative/qml/qdeclarativeengine.cpp | 50 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index d5910e3..2cae293 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -19,6 +19,8 @@ Animation: replace repeat with loops (loops: Animation.Infinite gives the old re AnchorChanges: use natural form to specify anchors (anchors.left instead of left) AnchorChanges: removed reset property. (reset: "left" should now be anchors.left: undefined) PathView: snapPosition replaced by preferredHighlightBegin, preferredHighlightEnd +createQmlObject: Moved to the Qt object, now use Qt.createQmlObject() +createComponent: Moved to the Qt object, now use Qt.createComponent() C++ API ------- diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index dc80ac4..0dd9368 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -254,19 +254,19 @@ QDeclarativeScriptEngine::QDeclarativeScriptEngine(QDeclarativeEnginePrivate *pr qtObject.setProperty(QLatin1String("quit"), newFunction(QDeclarativeEnginePrivate::quit, 0)); qtObject.setProperty(QLatin1String("resolvedUrl"),newFunction(QDeclarativeScriptEngine::resolvedUrl, 1)); + if (mainthread) { + qtObject.setProperty(QLatin1String("createQmlObject"), + newFunction(QDeclarativeEnginePrivate::createQmlObject, 1)); + qtObject.setProperty(QLatin1String("createComponent"), + newFunction(QDeclarativeEnginePrivate::createComponent, 1)); + } + //firebug/webkit compat QScriptValue consoleObject = newObject(); consoleObject.setProperty(QLatin1String("log"),newFunction(QDeclarativeEnginePrivate::consoleLog, 1)); consoleObject.setProperty(QLatin1String("debug"),newFunction(QDeclarativeEnginePrivate::consoleLog, 1)); globalObject().setProperty(QLatin1String("console"), consoleObject); - if (mainthread) { - globalObject().setProperty(QLatin1String("createQmlObject"), - newFunction(QDeclarativeEnginePrivate::createQmlObject, 1)); - globalObject().setProperty(QLatin1String("createComponent"), - newFunction(QDeclarativeEnginePrivate::createComponent, 1)); - } - // translation functions need to be installed // before the global script class is constructed (QTBUG-6437) installTranslatorFunctions(); @@ -1019,7 +1019,7 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS url = context->resolvedUrl(url); QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1)); - if(!parentArg) + if(!parentArg) return ctxt->throwError(QDeclarativeEngine::tr("parent object not found")); QDeclarativeComponent component(activeEngine); @@ -1027,10 +1027,21 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS if(component.isError()) { QList<QDeclarativeError> errors = component.errors(); - QString errstr = QLatin1String("Qt.createQmlObject(): "); - foreach (const QDeclarativeError &error, errors) + QString errstr = QLatin1String("Qt.createQmlObject() failed to create object: "); + QScriptValue arr = ctxt->engine()->newArray(errors.length()); + int i = 0; + foreach (const QDeclarativeError &error, errors){ errstr += QLatin1String(" ") + error.toString() + QLatin1String("\n"); - return ctxt->throwError(errstr); + QScriptValue qmlErrObject = ctxt->engine()->newObject(); + qmlErrObject.setProperty("lineNumber", QScriptValue(error.line())); + qmlErrObject.setProperty("columnNumber", QScriptValue(error.column())); + qmlErrObject.setProperty("fileName", QScriptValue(error.url())); + qmlErrObject.setProperty("message", QScriptValue(error.description())); + arr.setProperty(i++, qmlErrObject); + } + QScriptValue err = ctxt->throwError(errstr); + err.setProperty("qmlErrors",arr); + return err; } if (!component.isReady()) @@ -1040,10 +1051,21 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS if(component.isError()) { QList<QDeclarativeError> errors = component.errors(); - QString errstr = QLatin1String("Qt.createQmlObject(): "); - foreach (const QDeclarativeError &error, errors) + QString errstr = QLatin1String("Qt.createQmlObject() failed to create object: "); + QScriptValue arr = ctxt->engine()->newArray(errors.length()); + int i = 0; + foreach (const QDeclarativeError &error, errors){ errstr += QLatin1String(" ") + error.toString() + QLatin1String("\n"); - return ctxt->throwError(errstr); + QScriptValue qmlErrObject = ctxt->engine()->newObject(); + qmlErrObject.setProperty("lineNumber", QScriptValue(error.line())); + qmlErrObject.setProperty("columnNumber", QScriptValue(error.column())); + qmlErrObject.setProperty("fileName", QScriptValue(error.url())); + qmlErrObject.setProperty("message", QScriptValue(error.description())); + arr.setProperty(i++, qmlErrObject); + } + QScriptValue err = ctxt->throwError(errstr); + err.setProperty("qmlErrors",arr); + return err; } Q_ASSERT(obj); |