Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QScriptValue of array nth element

    General and Desktop
    1
    2
    580
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dextermagnific last edited by dextermagnific

      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

      1 Reply Last reply Reply Quote 0
      • D
        dextermagnific last edited by dextermagnific

        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"]
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post