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. Problem trying to create a QString matrix
QtWS25 Last Chance

Problem trying to create a QString matrix

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 357 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.
  • J Offline
    J Offline
    jss193
    wrote on last edited by
    #1

    Hello, I have created a model in which I wish items to be editable and I want to store items such as:

    private:
        int rows=0;
        int columns=5;
        int count = 1;
        QString m_gridData[rows][columns];
    

    in m_gridData are stored the values, but in my class I need the number of rows and columns to be dynamic since I add rows during execution time but this QString matrix need cols and rows not to be a class variables and it needs const int values...How can I to make this matrix size editable as I am running my app.

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Something like a QVector<QVector<QString>> ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • J Offline
        J Offline
        jss193
        wrote on last edited by
        #3

        Yes, by doing:

        QVector<QVector<QString> > *m_gridData = new QVector<QVector<QString> >;
        

        But how do I add values from data into rows and column?
        What I want is to store data written in a tableview column editable into this matrix and I don't know how to do it.

        Thanks

        jsulmJ 1 Reply Last reply
        0
        • J jss193

          Yes, by doing:

          QVector<QVector<QString> > *m_gridData = new QVector<QVector<QString> >;
          

          But how do I add values from data into rows and column?
          What I want is to store data written in a tableview column editable into this matrix and I don't know how to do it.

          Thanks

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @jss193 said in Problem trying to create a QString matrix:

          But how do I add values from data into rows and column?

          m_gridData[row][col] = "some string";
          

          If m_gridData really has to be a pointer (does it?):

          (*m_gridData)[row][col] = "some string";
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            There's usually no need to allocate your vector on the heap. Why do you need that ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2

            • Login

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