Qt Forum

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

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Creating a 2D map array in QML?

    QML and Qt Quick
    2
    2
    101
    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.
    • E
      E106JZ last edited by E106JZ

      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

      SGaist 1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion @E106JZ last edited by SGaist

        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 Reply Quote 1
        • First post
          Last post