QScript: How to pass in an array of objects to a javascript function
-
I want to create an array of object and pass them into Qt's Javascipt engine. I have no problem passing in an object itself, and have had no problem passing in an array of simple objects such as strings. But trying to pass an array of semi-simple objects has been elusive to me. Here is what I have
@QString function;
function.append("print(Person.name + ' age:' + Person.age);");
function.append("print(People[0].name);"); // how to print this out ?QScriptValue sv = engine.newObject();
QScriptValue svA = engine.newArray(2);QScriptValue person1;
person1.setProperty(name,"Larry");
person1.setProperty("age",32);
QScriptValue person2;
person2.setProperty(name,"Marry");
person2.setProperty("age",29);QScriptValue v1;
sv.setProperty("name","matt");
sv.setProperty("age",24);engine.globalObject().setProperty("Person",sv);
engine.globalObject().setProperty("People",svA);
searchFunction = engine.evaluate(function);@I only get the first print out.
matt age:24Must be a simple thing , but I have tried all sorts of permutations, with no success. I hope someone can please tell me the correct way to pass in an array of objects to a javascript function.
I am using Qt 5 with the script module by the way
Thanks
David