diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-02-15 21:05:45 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-02-15 21:05:45 +0100 |
commit | cf142cd637620e2af6ede46c4f2cefe0206d6159 (patch) | |
tree | 10ec6455b795a45152999e74335e5ae7f592903a /src/qml/jsapi | |
parent | 70f35501da4d1bbb36703dcc7b121c454f8d57a9 (diff) | |
parent | 238cc098d785b4fe76fbc8422b340d98ff8c1a1b (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: I2d4c012c8ca578f90d7eb56dbc6b306ac7cbb841
Diffstat (limited to 'src/qml/jsapi')
-rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index 048c5856ce..017eabd850 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -166,16 +166,30 @@ Q_DECLARE_METATYPE(QList<int>) properties of the proxy object. No binding code is needed because it is done dynamically using the Qt meta object system. + \snippet code/src_script_qjsengine.cpp 5 + Use newQMetaObject() to wrap a QMetaObject; this gives you a "script representation" of a QObject-based class. newQMetaObject() returns a proxy script object; enum values of the class are available as properties of the proxy object. - Constructors exposed to the meta-object system ( using Q_INVOKABLE ) can be + Constructors exposed to the meta-object system (using Q_INVOKABLE) can be called from the script to create a new QObject instance with - JavaScriptOwnership. + JavaScriptOwnership. For example, given the following class definition: - \snippet code/src_script_qjsengine.cpp 5 + \snippet code/src_script_qjsengine.cpp 7 + + The \c staticMetaObject for the class can be exposed to JavaScript like so: + + \snippet code/src_script_qjsengine.cpp 8 + + Instances of the class can then be created in JavaScript: + + \snippet code/src_script_qjsengine.cpp 9 + + \note Currently only classes using the Q_OBJECT macro are supported; it is + not possible to expose the \c staticMetaObject of a Q_GADGET class to + JavaScript. \section2 Dynamic QObject Properties @@ -541,7 +555,7 @@ QJSValue QJSEngine::newQObject(QObject *object) When called as a constructor, a new instance of the class will be created. Only constructors exposed by Q_INVOKABLE will be visible from the script engine. - \sa newQObject() + \sa newQObject(), {QObject Integration} */ QJSValue QJSEngine::newQMetaObject(const QMetaObject* metaObject) { @@ -558,7 +572,7 @@ QJSValue QJSEngine::newQMetaObject(const QMetaObject* metaObject) { Creates a JavaScript object that wraps the static QMetaObject associated with class \c{T}. - \sa newQObject() + \sa newQObject(), {QObject Integration} */ |