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

  1. registering c++ sequence container script engine, see qscriptregistersequencemetatype(). function's documentation has example int vector.

  2. use qscriptvalue function's argument. passed object can checked if array (qscriptvalue::isarray()) , accessed index using qscriptvalue::property()

option (2) works dictionaries (objects in javascript).


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -