diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-16 12:39:53 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-16 12:39:53 +0200 |
commit | 04b176d61fe8e7c351d86bf4cd8f2f4cb0f2d087 (patch) | |
tree | 803c92ba2b9821cb0c21d823b7d92baa97af6394 /src/qml/qml/v8 | |
parent | b7c4d7a25f6327657258acae46bd55a7e62b9b4e (diff) | |
parent | 852e60e67b7ee8e7aec9b89bbe26297b163b3cdc (diff) |
Merge remote-tracking branch 'origin/dev' into 5.8
Change-Id: Ib9f44a557bc1d9cf38058252efa0856c61f44c91
Diffstat (limited to 'src/qml/qml/v8')
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions.cpp | 37 | ||||
-rw-r--r-- | src/qml/qml/v8/qqmlbuiltinfunctions_p.h | 1 |
2 files changed, 32 insertions, 6 deletions
diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp index edc83b3bf1..5d70b17ece 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions.cpp +++ b/src/qml/qml/v8/qqmlbuiltinfunctions.cpp @@ -140,6 +140,7 @@ Heap::QtObject::QtObject(QQmlEngine *qmlEngine) o->defineDefaultProperty(QStringLiteral("darker"), QV4::QtObject::method_darker); o->defineDefaultProperty(QStringLiteral("tint"), QV4::QtObject::method_tint); o->defineDefaultProperty(QStringLiteral("quit"), QV4::QtObject::method_quit); + o->defineDefaultProperty(QStringLiteral("exit"), QV4::QtObject::method_exit); o->defineDefaultProperty(QStringLiteral("createQmlObject"), QV4::QtObject::method_createQmlObject); o->defineDefaultProperty(QStringLiteral("createComponent"), QV4::QtObject::method_createComponent); } @@ -995,6 +996,8 @@ This function causes the QQmlEngine::quit() signal to be emitted. Within the \l {Prototyping with qmlscene}, this causes the launcher application to exit; to quit a C++ application when this method is called, connect the QQmlEngine::quit() signal to the QCoreApplication::quit() slot. + +\sa exit() */ ReturnedValue QtObject::method_quit(CallContext *ctx) { @@ -1003,6 +1006,28 @@ ReturnedValue QtObject::method_quit(CallContext *ctx) } /*! + \qmlmethod Qt::exit(int retCode) + + This function causes the QQmlEngine::exit(int) signal to be emitted. + Within the \l {Prototyping with qmlscene}, this causes the launcher application to exit + the specified return code. To exit from the event loop with a specified return code when this + method is called, a C++ application can connect the QQmlEngine::exit(int) signal + to the QCoreApplication::exit(int) slot. + + \sa quit() +*/ +ReturnedValue QtObject::method_exit(CallContext *ctx) +{ + if (ctx->argc() != 1) + V4THROW_ERROR("Qt.exit(): Invalid arguments"); + + int retCode = ctx->args()[0].toNumber(); + + QQmlEnginePrivate::get(ctx->engine()->qmlEngine())->sendExit(retCode); + return QV4::Encode::undefined(); +} + +/*! \qmlmethod object Qt::createQmlObject(string qml, object parent, string filepath) Returns a new object created from the given \a string of QML which will have the specified \a parent, @@ -1035,7 +1060,9 @@ ReturnedValue QtObject::method_createQmlObject(CallContext *ctx) struct Error { static ReturnedValue create(QV4::ExecutionEngine *v4, const QList<QQmlError> &errors) { Scope scope(v4); - QString errorstr = QLatin1String("Qt.createQmlObject(): failed to create object: "); + QString errorstr; + // '+=' reserves extra capacity. Follow-up appending will be probably free. + errorstr += QLatin1String("Qt.createQmlObject(): failed to create object: "); QV4::ScopedArrayObject qmlerrors(scope, v4->newArrayObject()); QV4::ScopedObject qmlerror(scope); @@ -1490,15 +1517,13 @@ static QV4::ReturnedValue writeToConsole(ConsoleLogTypes logType, CallContext *c result.append(QLatin1Char(' ')); if (ctx->args()[i].as<ArrayObject>()) - result.append(QLatin1Char('[') + ctx->args()[i].toQStringNoThrow() + QLatin1Char(']')); + result += QLatin1Char('[') + ctx->args()[i].toQStringNoThrow() + QLatin1Char(']'); else result.append(ctx->args()[i].toQStringNoThrow()); } - if (printStack) { - result.append(QLatin1Char('\n')); - result.append(jsStack(v4)); - } + if (printStack) + result += QLatin1Char('\n') + jsStack(v4); static QLoggingCategory qmlLoggingCategory("qml"); static QLoggingCategory jsLoggingCategory("js"); diff --git a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h index d29983c476..8c0759679a 100644 --- a/src/qml/qml/v8/qqmlbuiltinfunctions_p.h +++ b/src/qml/qml/v8/qqmlbuiltinfunctions_p.h @@ -122,6 +122,7 @@ struct QtObject : Object static ReturnedValue method_btoa(CallContext *ctx); static ReturnedValue method_atob(CallContext *ctx); static ReturnedValue method_quit(CallContext *ctx); + static ReturnedValue method_exit(CallContext *ctx); static ReturnedValue method_resolvedUrl(CallContext *ctx); static ReturnedValue method_createQmlObject(CallContext *ctx); static ReturnedValue method_createComponent(CallContext *ctx); |