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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With