My table does't not dynamic update.
-
No problem, help me:)
-
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. -
As @Christian-Ehrlicher says. Start by checking your row number parameters to
beginInsertRows()
and which of the two models you are inserting into. -
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... -
Can you give me simple example for dynamic sort?
-
Can you give me simple example for dynamic sort?
-
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?
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 modelmodel
refers to. How should anyone answer? -
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?????
@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?