[Qt-interest] QTreeView and custom QAbstractItemModel performance problem

Felix Brack fb at ltec.ch
Fri Jul 9 11:57:49 CEST 2010


On 09.07.2010 11:32, Sean Harmer wrote:
> 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

Well, I had no hasChildren() until now... My new hasChildren() looks 
like this:

bool CMultiColumnListModel::hasChildren(const QModelIndex& Parent) const
{
   return (QModelIndex()==Parent);
}

Adding hasChildren() however does not change things with respect to 
performance and CPU load.

Felix



More information about the Qt-interest-old mailing list