Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. update QSqlDatabase and QTableView
Qt 6.12 LTS is out! See what's new in the release blog

update QSqlDatabase and QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 3 Posters 5.4k 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.
  • M Offline
    M Offline
    Mogli123
    wrote on last edited by
    #5

    That isn't defined at this moment, but not faster than every 5 seconds.

    JonBJ 1 Reply Last reply
    0
    • M Mogli123

      That isn't defined at this moment, but not faster than every 5 seconds.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #6

      @Mogli123
      If the data only comes from an array, do you need to save it in a database at all? You can tie a QTableView to a memory array without involving SQL/a database at all.

      Not sure what your best edit strategy should be, given that you won't allow user to make any changes from the UI view anyway....

      M 1 Reply Last reply
      0
      • JonBJ JonB

        @Mogli123
        If the data only comes from an array, do you need to save it in a database at all? You can tie a QTableView to a memory array without involving SQL/a database at all.

        Not sure what your best edit strategy should be, given that you won't allow user to make any changes from the UI view anyway....

        M Offline
        M Offline
        Mogli123
        wrote on last edited by Mogli123
        #7

        @JonB
        Thank you for your help.

        No, it isn't necessary to save the data in a database.
        Yes, I have to save the data in a database.
        I tried it this way because that is the only way I know...

        @JonB :
        "You can tie a QTableView to a memory array without involving SQL/a database at all."
        Is that a "better and easier" way to manage my problem?
        How can I do this?
        Furthermore, with the database I had the possibility to change the header data.
        In addition, at this time I have some hidden column with have for example the color information in it, which I need.
        This color information isn't in the array.
        Is that with your way possible, too?

        the table should look something like that
        0_1541497400730_Unbenannt.PNG

        Sorry if this is basic.

        JonBJ 1 Reply Last reply
        0
        • M Mogli123

          @JonB
          Thank you for your help.

          No, it isn't necessary to save the data in a database.
          Yes, I have to save the data in a database.
          I tried it this way because that is the only way I know...

          @JonB :
          "You can tie a QTableView to a memory array without involving SQL/a database at all."
          Is that a "better and easier" way to manage my problem?
          How can I do this?
          Furthermore, with the database I had the possibility to change the header data.
          In addition, at this time I have some hidden column with have for example the color information in it, which I need.
          This color information isn't in the array.
          Is that with your way possible, too?

          the table should look something like that
          0_1541497400730_Unbenannt.PNG

          Sorry if this is basic.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #8

          @Mogli123
          Let's take a step back!

          I think you are getting some data, which arrives in an array to your program, from some external source, which maybe sends new data every so often. Is that right?

          Forget Qt etc. for the moment. Do you or do you not wish to preserve that data in a database for some future purpose? If the answer turns out to be "No, I simply want to display the data in a table in the UI, when the program exits I'm happy for it to vanish" then you do not want to use a database/SQL! Instead look at http://doc.qt.io/qt-5/qstandarditemmodel.html, which is the basis for models which do not need SQL storage.

          M 1 Reply Last reply
          1
          • JonBJ JonB

            @Mogli123
            Let's take a step back!

            I think you are getting some data, which arrives in an array to your program, from some external source, which maybe sends new data every so often. Is that right?

            Forget Qt etc. for the moment. Do you or do you not wish to preserve that data in a database for some future purpose? If the answer turns out to be "No, I simply want to display the data in a table in the UI, when the program exits I'm happy for it to vanish" then you do not want to use a database/SQL! Instead look at http://doc.qt.io/qt-5/qstandarditemmodel.html, which is the basis for models which do not need SQL storage.

            M Offline
            M Offline
            Mogli123
            wrote on last edited by Mogli123
            #9

            @JonB

            Tank you.

            *I think you are getting some data, which arrives in an array to your program, from some external source, which maybe sends new data every so often. Is that right?

            Yes, exactly.
            I don't need the data in the future.
            I only have to display the data like in the picture, but not all of them. Some data I only need for the decision which color the row need, or other decisions. This data are at this time in hidden columns.

            JonBJ 1 Reply Last reply
            0
            • M Mogli123

              @JonB

              Tank you.

              *I think you are getting some data, which arrives in an array to your program, from some external source, which maybe sends new data every so often. Is that right?

              Yes, exactly.
              I don't need the data in the future.
              I only have to display the data like in the picture, but not all of them. Some data I only need for the decision which color the row need, or other decisions. This data are at this time in hidden columns.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #10

              @Mogli123
              So like I said: get rid of all SQL stuff, start out from QStandardItemModel (can be sub-classed if required), use that as your QTableView's model. (I said earlier you could use an array/QVector/whatever directly; I think you actually want to copy your data into a QStandardItemModel.) You can then insert/delete/update rows as your data arrives, and the view will update correspondingly.

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @Mogli123
                So like I said: get rid of all SQL stuff, start out from QStandardItemModel (can be sub-classed if required), use that as your QTableView's model. (I said earlier you could use an array/QVector/whatever directly; I think you actually want to copy your data into a QStandardItemModel.) You can then insert/delete/update rows as your data arrives, and the view will update correspondingly.

                M Offline
                M Offline
                Mogli123
                wrote on last edited by Mogli123
                #11

                @JonB
                Thank you very much for your help.

                I create my own model like shown in my code above.
                Is this with the QStandartItemModel possible on the same way?
                I need that for manipulating the data.

                How can I insert the data from my array (there are only qint32 in it) and how are they updating?
                Whit signal and slots?

                I know that are many questions and I'm very thankful for your help.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mogli123
                  wrote on last edited by Mogli123
                  #12

                  My boss just told me that he wants the data in a database.
                  He knows that it is not necessary at the moment, but later he needs the functions of a database.
                  So back to my original question, how can I update the database and the tableview?

                  I'm so sorry for this wrong information.

                  JonBJ 1 Reply Last reply
                  0
                  • M Mogli123

                    My boss just told me that he wants the data in a database.
                    He knows that it is not necessary at the moment, but later he needs the functions of a database.
                    So back to my original question, how can I update the database and the tableview?

                    I'm so sorry for this wrong information.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #13

                    @Mogli123
                    So then I said earlier:

                    You should update the model (QSqlTableModel, your TableCustomise) tied to the view with whatever data (e.g. http://doc.qt.io/qt-5/qsqltablemodel.html#setData, http://doc.qt.io/qt-5/qsqltablemodel.html#insertRecord) then the view will redraw to reflect that.

                    You need to read those, look at examples etc.

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      Mogli123
                      wrote on last edited by Mogli123
                      #14

                      Can you give me a smal example pleas how I have to do that?
                      That will be very helpfull.

                      Thank you very much.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Mogli123
                        wrote on last edited by
                        #15

                        @JonB
                        Thank you for your help:)
                        I tried it like this and it seems that it works

                        cpp
                        ...
                          myTableCustomiseToolChange->setEditStrategy(QSqlTableModel::OnFieldChange);
                        ...
                        //Methoden
                        ...
                        void test_screen::functionFuerTestwert()
                        {
                            arrayCustomiseToolChange[1] ++;
                            myTableCustomiseToolChange->setData(myTableCustomiseToolChange->index(1,2), arrayCustomiseToolChange[1]);
                        }
                        

                        is that the right way?

                        JonBJ 1 Reply Last reply
                        0
                        • M Mogli123

                          @JonB
                          Thank you for your help:)
                          I tried it like this and it seems that it works

                          cpp
                          ...
                            myTableCustomiseToolChange->setEditStrategy(QSqlTableModel::OnFieldChange);
                          ...
                          //Methoden
                          ...
                          void test_screen::functionFuerTestwert()
                          {
                              arrayCustomiseToolChange[1] ++;
                              myTableCustomiseToolChange->setData(myTableCustomiseToolChange->index(1,2), arrayCustomiseToolChange[1]);
                          }
                          

                          is that the right way?

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by
                          #16

                          @Mogli123
                          Yes, you seem to be using the model's setData() to alter values, which should be automatically reflected in the view, as per your original question.

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mogli123
                            wrote on last edited by
                            #17

                            @JonB
                            Thank you very much:)

                            Have a nice day.

                            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
                            • Unsolved