[Qt-interest] QTreeView and custom QAbstractItemModel performance problem

Andre Somers andre at familiesomers.nl
Fri Jul 9 13:58:36 CEST 2010


On 9-7-2010 13:50, Felix Brack wrote:
> On 09.07.2010 12:06, Andre Somers wrote:
>    
>> On 9-7-2010 11:57, Felix Brack wrote:
>>      
>>> an
>>> 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.
>>>
>>>        
>> If I understood you correctly, your model represents a table, right?
>> That means: no children to any of the items.
>>
>> If so, why not just implement the above as:
>>
>> bool CMultiColumnListModel::hasChildren(const QModelIndex&  Parent) const
>> {
>> Q_UNUSED(Parent)
>> return false;
>> }
>>
>>
>> André
>>
>>      
> In fact it is a table, yes. There is one root item. All rows have the
> root item as parent. Every row consist of the same number of columns.
> The existence of a root item leads to my code of hasChildren().
>
> Felix
>    
Hmmm... I see.

Would it be possible to ditch your root item and make it a real table? 
Or do you have other things in your view as well?
Wouldn't it be faster to test Parent.isValid() instead of comparing with 
a newly constructed QModelIndex every time?

André

-- 
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.




More information about the Qt-interest-old mailing list