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 884 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 last edited by
    #4

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

    JonBJ 1 Reply Last reply
    0
    • A architect23

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

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #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 last edited by
        #6

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

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #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 last edited by
            #8

            No problem, help me:)

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by Christian Ehrlicher
              #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
              • JonBJ Offline
                JonBJ Offline
                JonB
                wrote on 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 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.

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • A architect23

                    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.

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 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 last edited by
                      #13

                      Can you give me simple example for dynamic sort?

                      Pl45m4P 1 Reply Last reply
                      0
                      • A architect23

                        Can you give me simple example for dynamic sort?

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on 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 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?

                          JonBJ 1 Reply Last reply
                          0
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 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
                              		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?

                              JonBJ Offline
                              JonBJ Offline
                              JonB
                              wrote on 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 last edited by architect23
                                #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?????

                                JonBJ 1 Reply Last reply
                                0
                                • A architect23

                                  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?????

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #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

                                  • Login

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