[Qt-interest] QTreeView and custom QAbstractItemModel performance problem

Sean Harmer sean.harmer at maps-technology.com
Fri Jul 9 11:32:36 CEST 2010


On Friday 09 July 2010 09:44:01 Felix Brack wrote:
> I think the absolute time consumed by one of these functions (i.e.
> the function's performance) is not really relevant here.
> The real problem is that 304 calls to the function AppendRow() generate
> more then halve a million of calls to rowCount(), columnCount(), etc. In
> fact every call to AppendRow() generates r*c calls to these functions
> where r is the number of rows and c is the number columns in my list.

That seems odd. It's as if the view thinks that each of your items has 
children and is trying to find out how many children it has by calling 
rowCount() and columnCount() for each QModelIndex in your model. What does 
your implementation of hasChildren() look like please?

As others have suggested can you not just inherit your model from 
QAbstractTableModel as this takes care of this for you - ie hasChildren() 
returns false. It sounds like you have a table model or did I miss something?

Cheers,

Sean



More information about the Qt-interest-old mailing list