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

My table does't not dynamic update.

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 527 Views 1 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.
  • 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 15 days from now
      #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 15 days from now
          #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 Online
            J Online
            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 Online
                          J Online
                          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 Online
                              J Online
                              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

                              15/19

                              7 Mar 2025, 13:58

                              • Login

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