Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Creating a 2D map array in QML?

Creating a 2D map array in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 327 Views
  • 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.
  • E Offline
    E Offline
    E106JZ
    wrote on 30 Sept 2020, 13:36 last edited by E106JZ
    #1

    I'm not that well versed in JavaScript but I was trying to create a basic 2D map array with two keys (a string and integer) for accessing the value like this:

    var array = {}
    for (var x=0; x<5; x++)
    {
        array["test"][x] = x
    }
    

    But this gives me a TypeError: Type error on the array line when I run this code. How can I create a map like this at runtime and access it using a string and integer index using QML?

    Thanks

    S 1 Reply Last reply 30 Sept 2020, 18:36
    0
    • E E106JZ
      30 Sept 2020, 13:36

      I'm not that well versed in JavaScript but I was trying to create a basic 2D map array with two keys (a string and integer) for accessing the value like this:

      var array = {}
      for (var x=0; x<5; x++)
      {
          array["test"][x] = x
      }
      

      But this gives me a TypeError: Type error on the array line when I run this code. How can I create a map like this at runtime and access it using a string and integer index using QML?

      Thanks

      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 Sept 2020, 18:36 last edited by SGaist
      #2

      Hi,

      @E106JZ said in Creating a 2D map array in QML?:

      array["test"][ x ] = x

      You are using it as if it was a dict of dict which is wrong. If you want to do it like that you have to make the content of array["test"] a dict before filling it.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      1/2

      30 Sept 2020, 13:36

      • Login

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