1
我可以訪問傳入QJSEngine
的QObject
的屬性,但爲什麼我無法訪問動態屬性?在QJSEngine中訪問動態屬性
auto myObject = new MyObject(); // Contains a single property 'myProp'.
QJSEngine engine;
auto scriptMyObject = engine.newQObject(myObject);
engine.globalObject().setProperty("myObject" , scriptMyObject);
engine.evaluate("myObject.myProp = 4.2");
cout << engine.evaluate("myObject.myProp").toNumber() << endl;
myObject->setProperty("newProp", 35);
cout << myObject->property("newProp").toInt() << endl;
cout << engine.evaluate("myObject.newProp").toInt() << endl;
返回:
4.2
35
0
使用Qt 5.2。
你說得對,它似乎是迴歸。我在這裏打開了一個bug:https://bugreports.qt-project.org/browse/QTBUG-38181 – cmannett85
這不是一個錯誤,qt取消了對QJSEngine的支持:http://doc.qt.io /qt-5/qjsengine.html(搜索動態QObject屬性章節) – jaba