Solved How to achieve high performance asynchronous table model update?
-
Keep the model & view in a same thread & update the model here. Pull the data in worker thread. Use signals & slots between threads(worker -> UI ) to update the model. Avoid directly accessing the model directly from Worker thread.
-
Hi,
To add to @dheerendra, you can also do batch updates rather than updating each and every cell every time you have a change.
-
@SGaist Can you please elaborate a little bit on how to do batched updates?
-
If you have a high level of updates, only do emit dataChanged for e.g. 500 samples changed.
-
@SGaist @dheerendra Thanks to both of you for the tips.
-
@dheerendra said in How to achieve high performance asynchronous table model update?:
Use signals & slots between threads(worker -> UI ) to update the model. Avoid directly accessing the model directly from Worker thread.
I beg to differ. The worker should update the data interface, which is the model, not the view. The view shouldn't be known to the worker at all.
-
Another question: In a QTableView using a custom model subclassed off of QAbstractTableModel, how can one set the color of a cell based on comparing new and previous value of the cell? for example, if new value is higher than old set the cell background to green.
-
@JohnGa said in How to achieve high performance asynchronous table model update?:
Another question: In a QTableView using a custom model subclassed off of QAbstractTableModel, how can one set the color of a cell based on comparing new and previous value of the cell? for example, if new value is higher than old set the cell background to green.
You can do that in the QAbstractItemModel::setData override. When you find that you have different data, you can
setData
for the same cell (model index) but withQt::BackgroundRole
and provide a different color. -
@kshegunov wonder where I told to update the view from worker ?
-
@dheerendra said in How to achieve high performance asynchronous table model update?:
@kshegunov wonder where I told to update the view from worker ?
This is how I interpret the following (which I quoted already):
Use signals & slots between threads(worker -> UI ) to update the model.
The model is not UI, and you can update the model through the view, so I imagined this is what you meant.
-
@kshegunov Thanks for clarifications. Looks like my answer is misinterpreted.
Model is not UI & I did not say this also. Model can be updated from View & this is not in the context of his question.Now, worker Thread is pulling the data. Since model is in another thread use signals & slots to update the model which is in another thread. This is the only thing I said in my answer.