Howto dynamically modify 2D array of QvariantList?
Unsolved
General and Desktop
-
Hi all,
I want to dynamically create a 2D array of QVariantList to pass it to qml after (for plotting)
I cannot append any values to any qvariantlist inside a qvariantlist.
What I am doing wrong?
#include <QGuiApplication> #include <QQmlApplicationEngine> #include "QDebug" int main(int argc, char *argv[]) { #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); QVariantList list1; QVariantList list2; //create row0 list2.push_back("row0col1"); list2.push_back("row0col2"); list2.push_back("row0col3"); list2.push_back("row0col4"); list1.push_back(list2); qDebug() << "list1=" << list1; //create row1 list2[0].toList().push_back("row1col1"); list2[1].toList().push_back("row1col1"); list2[2].toList().push_back("row1col1"); list2[3].toList().push_back("row1col1"); qDebug() << "list1=" << list1; //noting append to list2 :( return app.exec(); }
import QtQuick 2.12 import QtQuick.Window 2.12 Window { width: 640 height: 480 visible: true title: qsTr("Hello World") }
Thanks
BRs
-
@lorenwell said in Howto dynamically modify 2D array of QvariantList?:
What I am doing wrong?
You forgot to add/replace list2 in list1 after you modified it.