Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScriptValue of array nth element
Qt 6.11 is out! See what's new in the release blog

QScriptValue of array nth element

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 857 Views 1 Watching
  • 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 Offline
    D Offline
    dextermagnific
    wrote on last edited by dextermagnific
    #1

    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
    0
    • D Offline
      D Offline
      dextermagnific
      wrote on last edited by dextermagnific
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved