How to push values to QML property variant two dimensional array - dynamically?
13,865
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.
Author by
Aquarius_Girl
Arts and Crafts.stackexchange.com is in public beta now. Join us!
Updated on June 30, 2022Comments
-
Aquarius_Girl almost 2 years
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?