[Qt-interest] QTreeView and custom QAbstractItemModel performance problem

Felix Brack fb at ltec.ch
Thu Jul 8 10:14:11 CEST 2010


Hello,

By subclassing QAbstractItemModel I have create a custom model that 
stores data from a communication trace row by row. Every row has 
multiple columns such as a time stamp, the data traced from the 
communication, etc. The number of rows in the data model is limited, 
let's say to 100 rows. When adding row 101 it is appended and the first 
row (i.e. the one with the oldest data) is removed.

To show the information to the user I use a QTreeView which shows each 
row of the data in the model line by line, i.e. the model is not 
hierarchic, all rows have the same parent (root) and consist of multiple 
columns.

Things are working so far but performance is very poor and the CPU load 
is incredible (even with just 100 rows). The reason for this is that 
whenever I append a row to the model the view calls the models 'data' 
member for all rows and all columns.

It seems that I'm missing something fundamental here and that appending 
a row of data to my model looks for the view like the entire data has 
changed. I will have to change something so only the data from the newly 
append row is queried by the view.

I just don't know how to do that... Can anybody push me into the right 
direction?

many thanks, Felix



More information about the Qt-interest-old mailing list