QScriptValue of array nth element



  • Hi everybody,

    I have big trouble getting the nth element of a QScriptValue array.

    let's suppose we have a JavaScript array:

    var a = [ o1, o2, o3 ];
    

    Where o1..o3 are objects of arbitrary type.

    Now I get the QScriptValue for this array:

    QScriptValue v = engine.property("a");
    

    Now, how do I retrieve (for example) object o2 given v ?

    If a were an object, I could do a "v.property()", but a is an array and I'm stuck here ...
    Thanks



  • Found it:

    QScriptValue o2 = v.property("1");
    

    because array indexes in JS are simply properties. The only thing is that you cannot write

    a.1;  // WRONG
    

    you must write

    a[1]
    

    or

    a["1"]
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.