[Qt-interest] Model/View speed of Models with many many items and item changes

Andreas Pakulat apaku at gmx.de
Sat Jun 13 00:26:05 CEST 2009


On 13.06.09 00:06:48, RZ wrote:
> 
> > The problem is probably that the standard models send a dataChanged() for each 
> > changed index.
> 
> I can strengthen that; doing
> 
> myModel->blockSignals(true);
> // manipulate lots of data
> myModel->blockSignals(false);

Thats a bad idea, at least you should do

bool block = myModel->blockSignals(true);
// do
myModel->blockSignals(false);

though this might be more "best practices" for widgets where it can
happen easier that a parent widget blocks and your subwidget enables its
signals without wanting it.
 
> improved speed about a factor of 100. I don't know why - but it worked ;-)

Well of course, because anything thats waiting for the various singals
that are being sent out won't get any while your changing the data. In
particular some views relayout their content on certain signals, so if
you update 10000 items in 10000 steps each time sending the signals, the
view might relayout each time. 

The same thing applies to changing data as well as adding/removing lots of rows or
columns. If you change more than a couple  (actual number depends on
your model/view/machine combination and maybe the position of the moon
;) you should make sure that you send out whatever change-signals are
usually sent only _once_ with all changed indices in it. That is only
one rowsAboutToBeInserted() and rowsInserted() signal for all rows,
instead of 10000 for each row individually.

Andreas

-- 
This will be a memorable month -- no matter how hard you try to forget it.



More information about the Qt-interest-old mailing list