Important: Please read the Qt Code of Conduct -

Creating a 2D map array in QML?

  • 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?


  • Lifetime Qt Champion


    @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.

Log in to reply