我可以访问QObject
传递给 a 的 s 的属性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。