I'm trying to pass a 2d QList as a Q_PROPERTY into QML, however, inside QML and i am unable to actually access any of the information.
some code:
c++: the q_property get populated by a q_invokable function in the constructor:
void Class::createNewGameArray(){
QList<QList<QString>> testArray;
for( int i = 0; i < _intervals.size(); ++i) {
QList<QString> innerArray;
testArray.append(innerArray);
testArray[i].append(_intervals[i]);
testArray[i].append("Audio");
}
for( int i = 0; i < _intervals.size(); ++i) {
QList<QString> innerArray;
testArray.append(innerArray);
testArray[i+12].append(_intervals[i]);
testArray[i+12].append("Text");
}
std::random_shuffle(testArray.begin(),testArray.end());
Class::setGameArray(testArray);
emit gameArrayChanged(_newGameArray);
which returns this:
(("M7", "Text"), ("M3", "Text"), ("m3", "Text"), ("M6", "Audio"), ("TT", "Audio"), ("P4", "Text"), ("m7", "Audio"), ("m2", "Text"), ("m6", "Audio"), ("m6", "Text"), ("M7", "Audio"), ("P5", "Text"), ("P4", "Audio"), ("m2", "Audio"), ("M2", "Audio"), ("M3", "Audio"), ("P5", "Audio"), ("m3", "Audio"), ("M6", "Text"), ("TT", "Text"), ("m7", "Text"), ("Oct", "Audio"), ("Oct", "Text"), ("M2", "Text"))
exactly what i want.
i set the rootContext like so in main.cpp:
Class object;
QQmlApplicationEngine engine;
QQmlContext* context = engine.rootContext();
context->setContextProperty("object", &object);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
however, inside qml i only get
qml: QVariant(QList<QList<QString> >)
and am unable to actually do anything with it.
My goal, ideally, would be to be able to access the 2d qlist from qml in this manner:
object.gameArray[0][1] // return "Text"
I'm able to do this with regular QLists (without the 2d). Any help would be greatly appreciated!