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
Forum Update on Monday, May 27th 2025

Problem trying to create a QString matrix

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 364 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 3 Jun 2019, 21:49 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Jun 2019, 21:58 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 3 Jun 2019, 22:17 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

        J 1 Reply Last reply 4 Jun 2019, 04:39
        0
        • J jss193
          3 Jun 2019, 22:17

          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

          J Online
          J Online
          jsulm
          Lifetime Qt Champion
          wrote on 4 Jun 2019, 04:39 last edited by jsulm 6 Apr 2019, 04:39
          #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
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 4 Jun 2019, 09:40 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

            5/5

            4 Jun 2019, 09:40

            • Login

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