diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-04-09 12:17:40 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-09 16:49:03 +0200 |
commit | 60730cbb5e5475b5db6a15641211aa6958a93197 (patch) | |
tree | c2dddee019f4f5367ba357bff358f94cc163367b /tests | |
parent | fc5314f96990148a7c32b988caf53c5db92b2b4b (diff) |
Add support for dynamic properties for QObjects in JavaScript
In QtScript you could add properties to a JS object that wraps a QObject.
Depending on the wrap option the property was either stored on the JavaScript
side or as dynamic QObject property.
In QJSEngine/QJSValue, neither was supported - properties could not be added.
For QObjects wrapped in JavaScript that weren't created by QML, we can restore
the behavior of storing dynamically added properties as JavaScript properties.
This makes porting from QtScript to QJS* much easier.
Task-number: QTBUG-37408
Change-Id: I5ef1f379c08c3d84de9bdcac9b6a9397238064de
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qjsengine/tst_qjsengine.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 7ef6bd9d2b..0a56c2f6d0 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -153,6 +153,8 @@ private slots: void prototypeChainGc(); + void dynamicProperties(); + signals: void testSignal(); }; @@ -2960,6 +2962,15 @@ void tst_QJSEngine::prototypeChainGc() QVERIFY(proto.isObject()); } +void tst_QJSEngine::dynamicProperties() +{ + QJSEngine engine; + QObject *obj = new QObject; + QJSValue wrapper = engine.newQObject(obj); + wrapper.setProperty("someRandomProperty", 42); + QCOMPARE(wrapper.property("someRandomProperty").toInt(), 42); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" |