Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push values to QML property variant two dimensional array - dynamically?

This is what I have tried:

import QtQuick 2.0

Rectangle
{
    property variant twoDimTempArray: [[]]
    property variant oneDArray: [1,2,3]

    MouseArea
    {
        anchors.fill: parent
        onClicked:
        {
            twoDimTempArray.push (oneDArray)

            twoDimTempArray[0].push (oneDArray)

            twoDimTempArray[0][0] = oneDArray[0]

            console.log (twoDimTempArray)
        }
    }
}

They all results in [].

How to push values in QML property variant two dimensional array?

like image 980
Aquarius_Girl Avatar asked Sep 29 '14 11:09

Aquarius_Girl


1 Answers

One way to add the values dynamically to a 1 dimensional QML variant is to fill a normal Javascript array and then assign it to the QML variant.

import QtQuick 2.0

Rectangle
{
    property variant oneDArray: []
    MouseArea
    {
        anchors.fill: parent
        onClicked:
        {
            var t = new Array (0)
            t.push(11)
            t.push(12)

            oneDArray = t

            console.log (oneDArray)
        }
    }
}

Output:

Starting /home/.../documents/test/build-junk-Desktop_Qt_5_1_0_GCC_64bit-Debug/junk...
QML debugging is enabled. Only use this in a safe environment.
[11,12]
/home/.../documents/test/build-junk-Desktop_Qt_5_1_0_GCC_64bit-Debug/junk exited with code 0

I have tried the same method for a 2 dimensional array and it works.

like image 189
Aquarius_Girl Avatar answered Oct 19 '22 11:10

Aquarius_Girl