javascript - Qt: How are arrays or dictionaries passed from qscriptengine? -
i've created qscriptengine , exposed object's function can call js script.
engine->globalobject().setproperty("obj", myobj); myobj qobject has function like...
void myobject::dosomething(int w, int h) { ... } and in js code, can call like...
obj.dosomething(5, 9); this works expect would, can't find docs on passing arrays or dictionaries these functions. example, if wanted pass array, how define c++ function this...
obj.dosomething([1,2,3], "foo"); would like...
void myobject::dosomething(qvector<qvariant> firstarg, qstring secondarg); it's hard work out when doesn't work, call seems silently fail.
for arrays have 2 options
registering c++ sequence container script engine, see
qscriptregistersequencemetatype(). function's documentation has example int vector.use
qscriptvaluefunction's argument. passed object can checked if array (qscriptvalue::isarray()) , accessed index usingqscriptvalue::property()
option (2) works dictionaries (objects in javascript).
Comments
Post a Comment