Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Howto dynamically modify 2D array of QvariantList?

Howto dynamically modify 2D array of QvariantList?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 245 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lorenwell
    wrote on last edited by lorenwell
    #1

    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

    Christian EhrlicherC 1 Reply Last reply
    0
    • L lorenwell

      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

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved