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.
-
@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?
-
-
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"
-
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?