From 08569a0981308f2d3c164d89aa4a00f321fd8e21 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Thu, 27 Jul 2017 11:47:28 +0200 Subject: QJSEngine: document limitation of dynamic QObject properties Dynamic QObject properties can not be accessed through C++ (via QJSValue) nor JavaScript. Task-number: QTBUG-38181 Change-Id: I78bb9898fef615a647234ae8df444e8855870258 Reviewed-by: Simon Hausmann --- src/qml/doc/snippets/code/src_script_qjsengine.cpp | 13 +++++++++++++ src/qml/jsapi/qjsengine.cpp | 7 ++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/qml/doc/snippets/code/src_script_qjsengine.cpp b/src/qml/doc/snippets/code/src_script_qjsengine.cpp index c9bd7dfcd9..0305574d34 100644 --- a/src/qml/doc/snippets/code/src_script_qjsengine.cpp +++ b/src/qml/doc/snippets/code/src_script_qjsengine.cpp @@ -91,3 +91,16 @@ myEngine.evaluate("button.checkable = true"); qDebug() << scriptButton.property("checkable").toBool(); scriptButton.property("show").call(); // call the show() slot //! [5] + + +//! [6] +QJSEngine engine; + +QObject *myQObject = new QObject(); +myQObject->setProperty("dynamicProperty", 3); + +QJSValue myScriptQObject = engine.newQObject(myQObject); +engine.globalObject().setProperty("myObject", myScriptQObject); + +qDebug() << engine.evaluate("myObject.dynamicProperty").toInt(); +//! [6] diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index e4c150057a..c678f8037a 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -175,9 +175,14 @@ Q_DECLARE_METATYPE(QList) called from the script to create a new QObject instance with JavaScriptOwnership. + \snippet code/src_script_qjsengine.cpp 5 + \section2 Dynamic QObject Properties - \snippet code/src_script_qjsengine.cpp 5 + Dynamic QObject properties are not supported. For example, the following code + will not work: + + \snippet code/src_script_qjsengine.cpp 6 \section1 Extensions -- cgit v1.2.3