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. tableView update content
Forum Updated to NodeBB v4.3 + New Features

tableView update content

Scheduled Pinned Locked Moved General and Desktop
tableviewupdatesignalslot
11 Posts 3 Posters 6.0k Views 3 Watching
  • 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.
  • K Offline
    K Offline
    koahnig
    wrote on last edited by
    #2

    Hi and welcome to devnet

    Do you have an event loop running?
    AFAIK the update should be automatically then. Anyway you can call the widget update, but this requires also that an event loop is running.

    PS: I have added markdown tags in your code section. This makes the code more readable. in the forum. You find the major tags at the end of this page.

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cpuin
      wrote on last edited by
      #3

      Thank you for your answer.
      i ran this.update(); but this update the Dialog.
      I need to update the tableView which belongs to the parent.
      Due to the event loop, my main.cpp looks like this

      QApplication a(argc, argv);

      InvoicePlusPlus w;
      
      QDesktopWidget *desktop = QApplication::desktop();
      
      screenWidth = desktop->width();
      screenHeight = desktop->height();
      
      x = (screenWidth - WIDTH) / 2;
      y = (screenHeight - HEIGHT) / 2;
      
      w.resize(WIDTH, HEIGHT);
      w.move( x, y );
      w.setWindowTitle("Invoice++");
      w.show();
      
      return a.exec();
      
      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #4

        The event loop shall be fine then.

        I never worked with SqlDatabase and model view, so I am not sure if you need to pull the information from the DB again.

        Vote the answer(s) that helped you to solve your issue(s)

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

          Hi and welcome to devnet,

          Since you are doing things low-level, then yes you have to refresh your model. Why not use QSqlTableModel to handle that ? You can hide the columns you don't want do see and do your update from it. That way both your views and your database will be up to date.

          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
          0
          • C Offline
            C Offline
            cpuin
            wrote on last edited by
            #6

            In my case, how to update the model?If you thing that the model should be updated, no the table.
            When i click another tab from my app and get back the table has being updated.It means that the model is updated, but the tableView didn't.

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

              If you want to update the model directly, you have to re-set the query on it. Again, since you are modifying your table, QSqlTableModel is better suited.

              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
              0
              • C Offline
                C Offline
                cpuin
                wrote on last edited by cpuin
                #8

                I switched to QSqlTableModel, it doesn't update by itself.How to do it?
                Also, can i set proxy to QSqlTableModel for filtering the result?

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

                  If you are still using QSqlQuery to update the database, you have to call select on the model

                  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
                  0
                  • C Offline
                    C Offline
                    cpuin
                    wrote on last edited by
                    #10

                    @cpuin said:

                    QSqlTableModel

                    i switched to QSqlTableModel.Unfortunatley the tableView doesn't update by it's self.
                    Do i have to update the model or the view.As i see the model is updated because when click another tab and get back the new record appears in the table.

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

                      Since you switched to QSqlTableModel, are you using it's functions to add new rows ?

                      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
                      0

                      • Login

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