Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, May 2008
QTreeView / QAbstractListModel issue


Message 1 in thread

I have a QTreeView with a very simple QAbstractListModel.

The model subclasses the following functions:

rowCount
columnCount
data
headerData

and that is it.

Now, the issue is as follows: The model freezes when being fed with
large amounts of data.

Large amounts being 200374 lines of data. CPU usage goes to 100% and I
can see that rowCount() is being called constantly over and over again
which I suspect is at least one of the problems.

Why is rowcount being called so often? Is there something I should be
doing that i'm not?

Normally I'd think that for ïQAbstractListModel rowCount should only be
called once since it's a List model and there are no child items to
query a rowcount for.

Thanks,

Stephan


--
 [ signature omitted ] 

Message 2 in thread

Hi,

"Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
news:g1l863$i19$1@xxxxxxxxxxxxxxxx
> I have a QTreeView with a very simple QAbstractListModel.
>
> The model subclasses the following functions:
>
> rowCount
> columnCount
> data
> headerData
>
> and that is it.
>
> Now, the issue is as follows: The model freezes when being fed with
> large amounts of data.
>
> Large amounts being 200374 lines of data. CPU usage goes to 100% and I
> can see that rowCount() is being called constantly over and over again
> which I suspect is at least one of the problems.
>
> Why is rowcount being called so often? Is there something I should be
> doing that i'm not?
>
> Normally I'd think that for ïQAbstractListModel rowCount should only be
> called once since it's a List model and there are no child items to
> query a rowcount for.

I don't know why rowCount is called so often, maybe it's an inefficient 
implementation by the Trolls. However, you can of course make sure that you 
optimize your implementation of rowCount in your model, so it caches the 
results.

However, what I found helps with speeding up display of large amounts of 
data is setting uniformRowHeights to true on your view. This will make 
displaying much faster.

HTH,

AndrÃ
 

--
 [ signature omitted ] 

Message 3 in thread

On Thu, 2008-05-29 at 09:08 +0200, Andrà Somers wrote:
> Hi,
> 
> "Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
> news:g1l863$i19$1@xxxxxxxxxxxxxxxx
> > I have a QTreeView with a very simple QAbstractListModel.
> >
> > The model subclasses the following functions:
> >
> > rowCount
> > columnCount
> > data
> > headerData
> >
> > and that is it.
> >
> > Now, the issue is as follows: The model freezes when being fed with
> > large amounts of data.
> >
> > Large amounts being 200374 lines of data. CPU usage goes to 100% and I
> > can see that rowCount() is being called constantly over and over again
> > which I suspect is at least one of the problems.
> >
> > Why is rowcount being called so often? Is there something I should be
> > doing that i'm not?
> >
> > Normally I'd think that for ïQAbstractListModel rowCount should only be
> > called once since it's a List model and there are no child items to
> > query a rowcount for.
> 
> I don't know why rowCount is called so often, maybe it's an inefficient 
> implementation by the Trolls. However, you can of course make sure that you 
> optimize your implementation of rowCount in your model, so it caches the 
> results.

Yea I was thinking of doing that last night but hadn't gotten to it yet.
I just tried it and that helped significantly. However, while the
process doesn't go hog the CPU for 10 minutes now, it's still far too
slow to be usable and there isn't anything else I can do to simplify the
rowCount function as it's reduced to just a return statement now.

> 
> However, what I found helps with speeding up display of large amounts of 
> data is setting uniformRowHeights to true on your view. This will make 
> displaying much faster.

I did that as well, didn't seem to make much of a difference on that
model. Really seems that all the time gets eaten up by excessive
rowCount and possibly other calls.

I just tried subclassing hasChildren as well but that unfortunately
didn't help.

Thanks,

Stephan


--
 [ signature omitted ] 

Message 4 in thread

On Thu, 2008-05-29 at 08:23 -0400, Stephan Rose wrote:
> On Thu, 2008-05-29 at 09:08 +0200, Andrà Somers wrote:
> > Hi,
> > 
> > "Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
> > news:g1l863$i19$1@xxxxxxxxxxxxxxxx
> > > I have a QTreeView with a very simple QAbstractListModel.
> > >
> > > The model subclasses the following functions:
> > >
> > > rowCount
> > > columnCount
> > > data
> > > headerData
> > >
> > > and that is it.
> > >
> > > Now, the issue is as follows: The model freezes when being fed with
> > > large amounts of data.
> > >
> > > Large amounts being 200374 lines of data. CPU usage goes to 100% and I
> > > can see that rowCount() is being called constantly over and over again
> > > which I suspect is at least one of the problems.
> > >
> > > Why is rowcount being called so often? Is there something I should be
> > > doing that i'm not?
> > >
> > > Normally I'd think that for ïQAbstractListModel rowCount should only be
> > > called once since it's a List model and there are no child items to
> > > query a rowcount for.
> > 
> > I don't know why rowCount is called so often, maybe it's an inefficient 
> > implementation by the Trolls. However, you can of course make sure that you 
> > optimize your implementation of rowCount in your model, so it caches the 
> > results.
> 
> Yea I was thinking of doing that last night but hadn't gotten to it yet.
> I just tried it and that helped significantly. However, while the
> process doesn't go hog the CPU for 10 minutes now, it's still far too
> slow to be usable and there isn't anything else I can do to simplify the
> rowCount function as it's reduced to just a return statement now.
> 
> > 
> > However, what I found helps with speeding up display of large amounts of 
> > data is setting uniformRowHeights to true on your view. This will make 
> > displaying much faster.
> 
> I did that as well, didn't seem to make much of a difference on that
> model. Really seems that all the time gets eaten up by excessive
> rowCount and possibly other calls.
> 
> I just tried subclassing hasChildren as well but that unfortunately
> didn't help.

Well I just discovered the problem, QT4.4

void QTreeViewPrivate::layout(int i)
{
    // Snip to line 2765
    for (int j = first; j < first + count; ++j) {
        current = model->index(j - first, firstColumn, parent);
    // Snip rest    
}

count = rowCount of model so the view is iterating through *all* items
not just the ones it needs to display.

I guess I may need to use a different class or create my own to display
the data, I'd rather avoid the last option though.

Any thoughts?

Thanks,

Stephan


--
 [ signature omitted ] 

Message 5 in thread

On 29.05.08 08:47:14, Stephan Rose wrote:
> On Thu, 2008-05-29 at 08:23 -0400, Stephan Rose wrote:
> > On Thu, 2008-05-29 at 09:08 +0200, Andrà Somers wrote:
> > > Hi,
> > > 
> > > "Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
> > > news:g1l863$i19$1@xxxxxxxxxxxxxxxx
> > > > I have a QTreeView with a very simple QAbstractListModel.
> > > >
> > > > The model subclasses the following functions:
> > > >
> > > > rowCount
> > > > columnCount
> > > > data
> > > > headerData
> > > >
> > > > and that is it.
> > > >
> > > > Now, the issue is as follows: The model freezes when being fed with
> > > > large amounts of data.
> > > >
> > > > Large amounts being 200374 lines of data. CPU usage goes to 100% and I
> > > > can see that rowCount() is being called constantly over and over again
> > > > which I suspect is at least one of the problems.
> > > >
> > > > Why is rowcount being called so often? Is there something I should be
> > > > doing that i'm not?
> > > >
> > > > Normally I'd think that for ïQAbstractListModel rowCount should only be
> > > > called once since it's a List model and there are no child items to
> > > > query a rowcount for.
> > > 
> > > I don't know why rowCount is called so often, maybe it's an inefficient 
> > > implementation by the Trolls. However, you can of course make sure that you 
> > > optimize your implementation of rowCount in your model, so it caches the 
> > > results.
> > 
> > Yea I was thinking of doing that last night but hadn't gotten to it yet.
> > I just tried it and that helped significantly. However, while the
> > process doesn't go hog the CPU for 10 minutes now, it's still far too
> > slow to be usable and there isn't anything else I can do to simplify the
> > rowCount function as it's reduced to just a return statement now.
> > 
> > > 
> > > However, what I found helps with speeding up display of large amounts of 
> > > data is setting uniformRowHeights to true on your view. This will make 
> > > displaying much faster.
> > 
> > I did that as well, didn't seem to make much of a difference on that
> > model. Really seems that all the time gets eaten up by excessive
> > rowCount and possibly other calls.
> > 
> > I just tried subclassing hasChildren as well but that unfortunately
> > didn't help.
> 
> Well I just discovered the problem, QT4.4
> 
> void QTreeViewPrivate::layout(int i)
> {
>     // Snip to line 2765
>     for (int j = first; j < first + count; ++j) {
>         current = model->index(j - first, firstColumn, parent);
>     // Snip rest    
> }
> 
> count = rowCount of model so the view is iterating through *all* items
> not just the ones it needs to display.

But it only calls index() which is supposed to be "really fast" and in
fact doesn't do anything in QAbstractListModel besides calling
createIndex with the input row+column, if hasIndex() returns true. Maybe
your hasIndex is slow?

Besides this would affect all models inside a QTreeView not just your
specific model.

Have you tried checking your model for "sanity" with the QModelTest
available at http://labs.trolltech.com/page/Projects/Itemview/Modeltest

Andreas

-- 
 [ signature omitted ] 

Message 6 in thread

On Thu, 2008-05-29 at 15:07 +0200, Andreas Pakulat wrote:
> On 29.05.08 08:47:14, Stephan Rose wrote:
> > On Thu, 2008-05-29 at 08:23 -0400, Stephan Rose wrote:
> > > On Thu, 2008-05-29 at 09:08 +0200, Andrà Somers wrote:
> > > > Hi,
> > > > 
> > > > "Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
> > > > news:g1l863$i19$1@xxxxxxxxxxxxxxxx
> > > > > I have a QTreeView with a very simple QAbstractListModel.
> > > > >
> > > > > The model subclasses the following functions:
> > > > >
> > > > > rowCount
> > > > > columnCount
> > > > > data
> > > > > headerData
> > > > >
> > > > > and that is it.
> > > > >
> > > > > Now, the issue is as follows: The model freezes when being fed with
> > > > > large amounts of data.
> > > > >
> > > > > Large amounts being 200374 lines of data. CPU usage goes to 100% and I
> > > > > can see that rowCount() is being called constantly over and over again
> > > > > which I suspect is at least one of the problems.
> > > > >
> > > > > Why is rowcount being called so often? Is there something I should be
> > > > > doing that i'm not?
> > > > >
> > > > > Normally I'd think that for ïQAbstractListModel rowCount should only be
> > > > > called once since it's a List model and there are no child items to
> > > > > query a rowcount for.
> > > > 
> > > > I don't know why rowCount is called so often, maybe it's an inefficient 
> > > > implementation by the Trolls. However, you can of course make sure that you 
> > > > optimize your implementation of rowCount in your model, so it caches the 
> > > > results.
> > > 
> > > Yea I was thinking of doing that last night but hadn't gotten to it yet.
> > > I just tried it and that helped significantly. However, while the
> > > process doesn't go hog the CPU for 10 minutes now, it's still far too
> > > slow to be usable and there isn't anything else I can do to simplify the
> > > rowCount function as it's reduced to just a return statement now.
> > > 
> > > > 
> > > > However, what I found helps with speeding up display of large amounts of 
> > > > data is setting uniformRowHeights to true on your view. This will make 
> > > > displaying much faster.
> > > 
> > > I did that as well, didn't seem to make much of a difference on that
> > > model. Really seems that all the time gets eaten up by excessive
> > > rowCount and possibly other calls.
> > > 
> > > I just tried subclassing hasChildren as well but that unfortunately
> > > didn't help.
> > 
> > Well I just discovered the problem, QT4.4
> > 
> > void QTreeViewPrivate::layout(int i)
> > {
> >     // Snip to line 2765
> >     for (int j = first; j < first + count; ++j) {
> >         current = model->index(j - first, firstColumn, parent);
> >     // Snip rest    
> > }
> > 
> > count = rowCount of model so the view is iterating through *all* items
> > not just the ones it needs to display.
> 
> But it only calls index() which is supposed to be "really fast" and in
> fact doesn't do anything in QAbstractListModel besides calling
> createIndex with the input row+column, if hasIndex() returns true. Maybe
> your hasIndex is slow?

hasIndex actually calls rowCount() and columnCount() so that is where
all the rowCount calls are coming from.

> Besides this would affect all models inside a QTreeView not just your
> specific model.

True, but this is the only model I have that has such a huge number of
data items, which is why I noticed it. The next closest model only has
about 40k data items, which *may* actually be a problem on some of the
slower machines as those already get a bit laggy (though still within
reason) with ~5k items.

> 
> Have you tried checking your model for "sanity" with the QModelTest
> available at http://labs.trolltech.com/page/Projects/Itemview/Modeltest

Not a bad idea, I may throw it at that. Though what I subclass is so
simple it'd be tough to do it any differently. 

Thanks,

Stephan


--
 [ signature omitted ] 

Message 7 in thread

Stephan Rose wrote:
> On Thu, 2008-05-29 at 08:23 -0400, Stephan Rose wrote:
>   
>> On Thu, 2008-05-29 at 09:08 +0200, Andrà Somers wrote:
>>     
>>> Hi,
>>>
>>> "Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
>>> news:g1l863$i19$1@xxxxxxxxxxxxxxxx
>>>       
>>>> I have a QTreeView with a very simple QAbstractListModel.
>>>>
>>>> The model subclasses the following functions:
>>>>
>>>> rowCount
>>>> columnCount
>>>> data
>>>> headerData
>>>>
>>>> and that is it.
>>>>
>>>> Now, the issue is as follows: The model freezes when being fed with
>>>> large amounts of data.
>>>>
>>>> Large amounts being 200374 lines of data. CPU usage goes to 100% and I
>>>> can see that rowCount() is being called constantly over and over again
>>>> which I suspect is at least one of the problems.
>>>>
>>>> Why is rowcount being called so often? Is there something I should be
>>>> doing that i'm not?
>>>>
>>>> Normally I'd think that for ïQAbstractListModel rowCount should only be
>>>> called once since it's a List model and there are no child items to
>>>> query a rowcount for.
>>>>         
>>> I don't know why rowCount is called so often, maybe it's an inefficient 
>>> implementation by the Trolls. However, you can of course make sure that you 
>>> optimize your implementation of rowCount in your model, so it caches the 
>>> results.
>>>       
>> Yea I was thinking of doing that last night but hadn't gotten to it yet.
>> I just tried it and that helped significantly. However, while the
>> process doesn't go hog the CPU for 10 minutes now, it's still far too
>> slow to be usable and there isn't anything else I can do to simplify the
>> rowCount function as it's reduced to just a return statement now.
>>
>>     
>>> However, what I found helps with speeding up display of large amounts of 
>>> data is setting uniformRowHeights to true on your view. This will make 
>>> displaying much faster.
>>>       
>> I did that as well, didn't seem to make much of a difference on that
>> model. Really seems that all the time gets eaten up by excessive
>> rowCount and possibly other calls.
>>
>> I just tried subclassing hasChildren as well but that unfortunately
>> didn't help.
>>     
>
> Well I just discovered the problem, QT4.4
>
> void QTreeViewPrivate::layout(int i)
> {
>     // Snip to line 2765
>     for (int j = first; j < first + count; ++j) {
>         current = model->index(j - first, firstColumn, parent);
>     // Snip rest    
> }
>
> count = rowCount of model so the view is iterating through *all* items
> not just the ones it needs to display.
>
> I guess I may need to use a different class or create my own to display
> the data, I'd rather avoid the last option though.
>
> Any thoughts?
>
>   

Sounds like a bug in 4.4. I'd report this to qt-bugs@xxxxxxxxxxxxxx

However, is there any reason you aren't you using QListView or 
QTableView if your data model is just a list?  These classes are much 
faster as they do not need to account for any type of tree maintenance 
like the possibility of expanding and collapsing nodes.

Good Luck,
--Justin

begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk.;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:617-621-0060
x-mozilla-html:FALSE
url:www.ics.com
version:2.1
end:vcard


Message 8 in thread

On Thu, 2008-05-29 at 09:16 -0400, Justin Noel wrote:
> Stephan Rose wrote:
> > On Thu, 2008-05-29 at 08:23 -0400, Stephan Rose wrote:
> >   
> >> On Thu, 2008-05-29 at 09:08 +0200, Andrà Somers wrote:
> >>     
> >>> Hi,
> >>>
> >>> "Stephan Rose" <kermos@xxxxxxxxxx> wrote in message 
> >>> news:g1l863$i19$1@xxxxxxxxxxxxxxxx
> >>>       
> >>>> I have a QTreeView with a very simple QAbstractListModel.
> >>>>
> >>>> The model subclasses the following functions:
> >>>>
> >>>> rowCount
> >>>> columnCount
> >>>> data
> >>>> headerData
> >>>>
> >>>> and that is it.
> >>>>
> >>>> Now, the issue is as follows: The model freezes when being fed with
> >>>> large amounts of data.
> >>>>
> >>>> Large amounts being 200374 lines of data. CPU usage goes to 100% and I
> >>>> can see that rowCount() is being called constantly over and over again
> >>>> which I suspect is at least one of the problems.
> >>>>
> >>>> Why is rowcount being called so often? Is there something I should be
> >>>> doing that i'm not?
> >>>>
> >>>> Normally I'd think that for ïQAbstractListModel rowCount should only be
> >>>> called once since it's a List model and there are no child items to
> >>>> query a rowcount for.
> >>>>         
> >>> I don't know why rowCount is called so often, maybe it's an inefficient 
> >>> implementation by the Trolls. However, you can of course make sure that you 
> >>> optimize your implementation of rowCount in your model, so it caches the 
> >>> results.
> >>>       
> >> Yea I was thinking of doing that last night but hadn't gotten to it yet.
> >> I just tried it and that helped significantly. However, while the
> >> process doesn't go hog the CPU for 10 minutes now, it's still far too
> >> slow to be usable and there isn't anything else I can do to simplify the
> >> rowCount function as it's reduced to just a return statement now.
> >>
> >>     
> >>> However, what I found helps with speeding up display of large amounts of 
> >>> data is setting uniformRowHeights to true on your view. This will make 
> >>> displaying much faster.
> >>>       
> >> I did that as well, didn't seem to make much of a difference on that
> >> model. Really seems that all the time gets eaten up by excessive
> >> rowCount and possibly other calls.
> >>
> >> I just tried subclassing hasChildren as well but that unfortunately
> >> didn't help.
> >>     
> >
> > Well I just discovered the problem, QT4.4
> >
> > void QTreeViewPrivate::layout(int i)
> > {
> >     // Snip to line 2765
> >     for (int j = first; j < first + count; ++j) {
> >         current = model->index(j - first, firstColumn, parent);
> >     // Snip rest    
> > }
> >
> > count = rowCount of model so the view is iterating through *all* items
> > not just the ones it needs to display.
> >
> > I guess I may need to use a different class or create my own to display
> > the data, I'd rather avoid the last option though.
> >
> > Any thoughts?
> >
> >   
> 
> Sounds like a bug in 4.4. I'd report this to qt-bugs@xxxxxxxxxxxxxx
> 
> However, is there any reason you aren't you using QListView or 
> QTableView if your data model is just a list?  These classes are much 
> faster as they do not need to account for any type of tree maintenance 
> like the possibility of expanding and collapsing nodes.

Yea, the QTreeView has *exactly* the look and feel I want.

QListView has no support for columns that I'm aware of and I need
columns.

QTableView may have columns, but it feels and acts too grid-like, not
what I want.

The QTreeView is essentially perfect from it's look and feel. It'd be
really great if there was a class added to QT that essentially is like
QTreeView without the "tree" part of it. Just a multi-column capable
list optimized for that purpose would be absolutely awesome.

Thanks,

Stephan



--
 [ signature omitted ] 

Message 9 in thread

Stephan,

QTreeView is designed for "tree type" data presentation.
QTable is designed for two dimensional data presentation.

That is a major difference. QTreeView row presentation depends on the
state of the items above. So QTreeView implementation can't be as
efficient as QTableView implementation. It might be or it might be not
the way to improve it in your specific case, but in general, if you need
two dimensional data presentation, QTableView is a right choice.

Look and feel? It is pretty customizable as is, and if you are not
satisfied with some elements, it might be a good idea to spend some time
modifying them instead of chosing the widget which can't efficiently
represent your data by design.
 
I might be wrong, but it seems pretty easy to make QTableView look like
QTreeView "without tree part". 

Best regards

Alex Malyushytsky
Research Engineer - Weidlinger Associates Inc.

>>Yea, the QTreeView has *exactly* the look and feel I want.
>>QTableView may have columns, but it feels and acts too grid-like, not
>>what I want.
>>
>>The QTreeView is essentially perfect from it's look and feel. It'd be
>>really great if there was a class added to QT that essentially is like
>>QTreeView without the "tree" part of it. Just a multi-column capable
>>list optimized for that purpose would be absolutely awesome.
>>
>>Thanks,
>>
>>Stephan

--
 [ signature omitted ] 

Message 10 in thread

Malyushytsky, Alex wrote:
> QTreeView is designed for "tree type" data presentation.
> QTable is designed for two dimensional data presentation.
> 
> That is a major difference. QTreeView row presentation depends on the
> state of the items above. So QTreeView implementation can't be as
> efficient as QTableView implementation. It might be or it might be not
> the way to improve it in your specific case, but in general, 
> if you need
> two dimensional data presentation, QTableView is a right choice.

i think i have read on this list on several occurences, that QTreeView
actually offers better performance than QTableView for large
multi-column tables.

e.g. http://lists.trolltech.com/qt-interest/2008-02/thread00312-0.html

To the OP: Just make sure before you invest any time into QTableView
that it *really* is faster for you. It could very well be that it is
slower.

Cheers,
Peter

--
 [ signature omitted ] 

Message 11 in thread

> i think i have read on this list on several occurences, that QTreeView
> actually offers better performance than QTableView for large
> multi-column tables.

This is not true. QTableView is faster then QTreeView at displaying a table. 
QTreeView has to do a lot of extra work because it also deals with trees.  
With a little tweaking QTableView can be *much* faster and contains way more 
data with less memory overhead.  A little bit ago I made a little app that 
contained over 100 million rows with a memory consumption of only around 
800MB

http://www.kdedevelopers.org/node/2491

-Benjamin Meyer

--
 [ signature omitted ] 

Message 12 in thread

> The QTreeView is essentially perfect from it's look and feel. It'd be
> really great if there was a class added to QT that essentially is like
> QTreeView without the "tree" part of it. Just a multi-column capable
> list optimized for that purpose would be absolutely awesome.
>com/qt-interest/

Sounds like a QTableView to me.  Just hide the vertical header and turn off 
the grid.

-Benjamin Meyer

--
 [ signature omitted ]