Search code examples
c++qtqml

Pass 2d Array from c++ to qml


The question is above. I can create a 2d array in qml like this:

function create()
{
    var array= new Array(9);
    array[0]= new Array(
}

So how I can create such array in c++? I tried:

QVariant myArray= QVariant([4,5,6,7]);

but this doesn't work.


Solution

  • You can use QVariantList which could be passed to qml:

    QVariantList list;
    list.append(QVariantList{5, 5, 6, 7});