PDA

View Full Version : I dont want to update QTableView after every beginInsertRows()



mikemc
7th June 2011, 20:12
Hi!

I am using QTableView which is connected with some model. In the model the data is changing very fast in the background.

Is it possible to update the QTableView for example only every second?

Greetings from Vienna

Mike

Santosh Reddy
7th June 2011, 23:49
I don't think there is direct way to do so.

One way to do so is to maintain a internal state in the model, and give new data to the view only when you want it to get updated ( by emitting reset() signal from model). You need to accordingly handle all the model interface calls (rowCount(), columnCount(), data(), index(), setData(), etc).

Another way (with out maintaining internal state in model) would to maintain two instances of model, one for updating in background (not connected to any views), another to display (connected to views), when ever you wan the views to get updated, just switch the model, and use the other one for background updating again. Decision has to made keeping various factors like typical size of model, typical time to update the complete model, typical refresh time etc.

mikemc
8th June 2011, 16:39
Hi Santosh,

Thxs for your answere!
It seems that I need a separate model for the TableView.

I am not sure if I understood your solution with the reset signal. You mean, when adding or delete data to the model, I dont call beginInsertRows(), but before updating the TableView I have to call model->modelReset()?
I think this is very expensive or?

Santosh Reddy
8th June 2011, 18:16
I was suggesting to have two models

mikemc
8th June 2011, 20:11
I meant your first way

wysota
8th June 2011, 20:37
Is it possible to update the QTableView for example only every second?
Sure. Have a timer in your model that will fire once a second. Store all the changes to the incoming model in a waiting queue and process the queue (inserting the data into the model) when the timer fires.