My table does't not dynamic update.
-
wrote on 7 Mar 2025, 09:34 last edited by
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); <-----------------
-
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); <-----------------
@architect23 Isn't your proxyModel a local variable which is deleted as soon as it leaves its scope?
-
wrote on 7 Mar 2025, 10:40 last edited by
it is field of class(global variable)
-
wrote on 7 Mar 2025, 10:42 last edited by
simple sort by header column is worked, but dynamic does't work
-
simple sort by header column is worked, but dynamic does't work
wrote on 7 Mar 2025, 10:49 last edited by JonB 3 Jul 2025, 10:49@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? -
wrote on 7 Mar 2025, 11:46 last edited by
I solved my problem:
before beginInsertRows(), I set beginResetModel() and after endInsertRows(), I set endResetModel() -
Lifetime Qt Championwrote on 7 Mar 2025, 11:57 last edited by Christian Ehrlicher 3 Jul 2025, 11:57
This is no solution but a hacky workaround... You should better fix your problem instead.
-
wrote on 7 Mar 2025, 12:24 last edited by
No problem, help me:)
-
Lifetime Qt Championwrote on 7 Mar 2025, 12:49 last edited by Christian Ehrlicher 3 Jul 2025, 12:51
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. -
wrote on 7 Mar 2025, 12:59 last edited by
As @Christian-Ehrlicher says. Start by checking your row number parameters to
beginInsertRows()
and which of the two models you are inserting into. -
wrote on 7 Mar 2025, 13:24 last edited by
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.
-
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.
@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... -
wrote on 7 Mar 2025, 13:29 last edited by
Can you give me simple example for dynamic sort?
-
Can you give me simple example for dynamic sort?
-
wrote on 7 Mar 2025, 13:58 last edited by
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?
-
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"
-
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?
wrote on 7 Mar 2025, 14:01 last edited byIn 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 modelmodel
refers to. How should anyone answer? -
wrote on 10 Mar 2025, 09:52 last edited by architect23 3 Oct 2025, 09:55
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?????
-
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?????
wrote on 10 Mar 2025, 10:10 last edited by JonB 3 Oct 2025, 10:10@architect23
Since the code is identical the difference must come from either the value offilterNode
versusnew_row
or the content of the node pointed to byparent_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?
7/19