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. My table does't not dynamic update.
Forum Update on Monday, May 27th 2025

My table does't not dynamic update.

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 494 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.
  • A Offline
    A Offline
    architect23
    wrote on 7 Mar 2025, 09:34 last edited by
    #1

    I have next code, but my tableview does't update dynamic, where I wrong?

    QSortFilterProxyModel proxyModel;
    proxyModel.setSourceModel(&m_myModel);
    tableView->setModel(&proxyModel);
    tableView->setSortingEnabled(true);
    proxyModel.setDynamicSortFilter(true); <-----------------
    
    J 1 Reply Last reply 7 Mar 2025, 10:07
    0
    • A architect23
      7 Mar 2025, 09:34

      I have next code, but my tableview does't update dynamic, where I wrong?

      QSortFilterProxyModel proxyModel;
      proxyModel.setSourceModel(&m_myModel);
      tableView->setModel(&proxyModel);
      tableView->setSortingEnabled(true);
      proxyModel.setDynamicSortFilter(true); <-----------------
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 7 Mar 2025, 10:07 last edited by
      #2

      @architect23 Isn't your proxyModel a local variable which is deleted as soon as it leaves its scope?

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        architect23
        wrote on 7 Mar 2025, 10:40 last edited by
        #3

        it is field of class(global variable)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          architect23
          wrote on 7 Mar 2025, 10:42 last edited by
          #4

          simple sort by header column is worked, but dynamic does't work

          J 1 Reply Last reply 7 Mar 2025, 10:49
          0
          • A architect23
            7 Mar 2025, 10:42

            simple sort by header column is worked, but dynamic does't work

            J Offline
            J Offline
            JonB
            wrote on 7 Mar 2025, 10:49 last edited by JonB 3 Jul 2025, 10:49
            #5

            @architect23
            How do we know "dynamic does't work"? What do you do to cause it to be activated, how does it come out and what should it be? In the sample you provide what column are you expecting it to be sorted by anyway?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              architect23
              wrote on 7 Mar 2025, 11:46 last edited by
              #6

              I solved my problem:
              before beginInsertRows(), I set beginResetModel() and after endInsertRows(), I set endResetModel()

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 7 Mar 2025, 11:57 last edited by Christian Ehrlicher 3 Jul 2025, 11:57
                #7

                This is no solution but a hacky workaround... You should better fix your problem instead.

                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
                1
                • A Offline
                  A Offline
                  architect23
                  wrote on 7 Mar 2025, 12:24 last edited by
                  #8

                  No problem, help me:)

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 7 Mar 2025, 12:49 last edited by Christian Ehrlicher 3 Jul 2025, 12:51
                    #9

                    You don't post valid, compileable code, how should we help?
                    This problem could be stripped down to maybe 50 lines of code. If you provide it and it still does not work we might be able to help.

                    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
                    1
                    • J Offline
                      J Offline
                      JonB
                      wrote on 7 Mar 2025, 12:59 last edited by
                      #10

                      As @Christian-Ehrlicher says. Start by checking your row number parameters to beginInsertRows() and which of the two models you are inserting into.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        architect23
                        wrote on 7 Mar 2025, 13:24 last edited by
                        #11

                        On the contrary, I just gave a piece of code where a sorting model was created and some methods were applied to it. If something was missing, then I expected to hear this: why do you need my entire code? No one will look at it.

                        C 1 Reply Last reply 7 Mar 2025, 13:29
                        0
                        • A architect23
                          7 Mar 2025, 13:24

                          On the contrary, I just gave a piece of code where a sorting model was created and some methods were applied to it. If something was missing, then I expected to hear this: why do you need my entire code? No one will look at it.

                          C Offline
                          C Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on 7 Mar 2025, 13:29 last edited by
                          #12

                          @architect23 said in My table does't not dynamic update.:

                          No one will look at it.

                          Correct, therefore I requested a minimal, compilable example - as I already wrote I would guess it's not more than 50 lines of code.
                          The code you gave told us only that you create a local QSortFilterProxyModel which will be destructed on function exit. Also you did not show use where and how you update the data...

                          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
                          1
                          • A Offline
                            A Offline
                            architect23
                            wrote on 7 Mar 2025, 13:29 last edited by
                            #13

                            Can you give me simple example for dynamic sort?

                            P 1 Reply Last reply 7 Mar 2025, 13:52
                            0
                            • A architect23
                              7 Mar 2025, 13:29

                              Can you give me simple example for dynamic sort?

                              P Offline
                              P Offline
                              Pl45m4
                              wrote on 7 Mar 2025, 13:52 last edited by
                              #14

                              @architect23

                              https://doc.qt.io/qt-6/qtwidgets-itemviews-customsortfiltermodel-example.html


                              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                              ~E. W. Dijkstra

                              1 Reply Last reply
                              1
                              • A Offline
                                A Offline
                                architect23
                                wrote on 7 Mar 2025, 13:58 last edited by
                                #15
                                		QVariant lhs_data = model->data(left, Qt::DisplayRole);<-------------- 0.00
                                		QVariant rhs_data = model->data(right, Qt::DisplayRole);<--------------5.37
                                

                                In first string I always get zero, I don't understand why?

                                J 1 Reply Last reply 7 Mar 2025, 14:01
                                0
                                • C Offline
                                  C Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on 7 Mar 2025, 14:00 last edited by
                                  #16

                                  This example works fine for me, prove us that there is an error in Qt:

                                  int main(int argc, char* argv[])
                                  {
                                  	QApplication app(argc, argv);
                                  	QTableView tv;
                                  	tv.setSortingEnabled(true);
                                  	auto model = new QStandardItemModel;
                                  	for (int i = 0; i < 10; ++i)
                                  		model->appendRow(new QStandardItem(QString::number(i + 1)));
                                  	auto proxy = new QSortFilterProxyModel;
                                  	proxy->setSourceModel(model);
                                  	proxy->sort(0);
                                  	proxy->setDynamicSortFilter(true);
                                  	QTimer t;
                                  	t.start(1000);
                                  	auto rand = QRandomGenerator::global();
                                  	QObject::connect(&t, &QTimer::timeout, [&]() {
                                  		int row = rand->bounded(0, 9);
                                  		auto item = model->item(row);
                                  		item->setText(QString::number(rand->bounded(1, 200)));
                                  	});
                                  	tv.setModel(proxy);
                                  	tv.show();
                                  	return app.exec();
                                  }
                                  

                                  Attention: It sorts by DisplayRole so "123" < "80"

                                  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
                                  1
                                  • A architect23
                                    7 Mar 2025, 13:58
                                    		QVariant lhs_data = model->data(left, Qt::DisplayRole);<-------------- 0.00
                                    		QVariant rhs_data = model->data(right, Qt::DisplayRole);<--------------5.37
                                    

                                    In first string I always get zero, I don't understand why?

                                    J Offline
                                    J Offline
                                    JonB
                                    wrote on 7 Mar 2025, 14:01 last edited by
                                    #17

                                    @architect23

                                    In first string I always get zero, I don't understand why?

                                    Depends what data you have in model->data(left), which nobody but you knows, and for that matter which model model refers to. How should anyone answer?

                                    1 Reply Last reply
                                    0
                                    • A Offline
                                      A Offline
                                      architect23
                                      wrote on 10 Mar 2025, 09:52 last edited by architect23 3 Oct 2025, 09:55
                                      #18

                                      I solved my problem, no dynamic sort because no data yet, but I don't understand I have two string with two function:
                                      function1()
                                      function2()
                                      in function1():

                                      beginInsertRows(model_index, parent_filter->rowCount(), parent_filter->rowCount());
                                      	parent_filter->InsertChild(filterNode);
                                      	endInsertRows();
                                      

                                      and it callback function lessThan()-OK
                                      in function2():

                                      beginInsertRows(model_index, parent_filter->rowCount(), parent_filter->rowCount());
                                      	parent_filter->InsertChild(new_row);
                                      	endInsertRows();
                                      

                                      but it did't callback lessThan() after endInsertRows()-why?????

                                      J 1 Reply Last reply 10 Mar 2025, 10:10
                                      0
                                      • A architect23
                                        10 Mar 2025, 09:52

                                        I solved my problem, no dynamic sort because no data yet, but I don't understand I have two string with two function:
                                        function1()
                                        function2()
                                        in function1():

                                        beginInsertRows(model_index, parent_filter->rowCount(), parent_filter->rowCount());
                                        	parent_filter->InsertChild(filterNode);
                                        	endInsertRows();
                                        

                                        and it callback function lessThan()-OK
                                        in function2():

                                        beginInsertRows(model_index, parent_filter->rowCount(), parent_filter->rowCount());
                                        	parent_filter->InsertChild(new_row);
                                        	endInsertRows();
                                        

                                        but it did't callback lessThan() after endInsertRows()-why?????

                                        J Offline
                                        J Offline
                                        JonB
                                        wrote on 10 Mar 2025, 10:10 last edited by JonB 3 Oct 2025, 10:10
                                        #19

                                        @architect23
                                        Since the code is identical the difference must come from either the value of filterNode versus new_row or the content of the node pointed to by parent_filter.

                                        Maybe lessThan(), which is needed for sorting, is not called because e.g. parent_filter has no children in one case so it does not need to compare to sort?

                                        1 Reply Last reply
                                        0

                                        7/19

                                        7 Mar 2025, 11:57

                                        12 unread
                                        • Login

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