[Qt-interest] Why QListView is so slow and QTableView is fast?

Kenneth Beck nekkceb at comcast.net
Thu Aug 27 05:14:01 CEST 2009


Justin Noel wrote:
> Kenneth Beck wrote:
>> Sylvain Pointeau wrote:
>>   
>>> Hi,
>>>
>>> I am testing QListView for a large number of items (36'000)...
>>> it is so sloooow (I stopped the application, it never shows up) .
>>> (yes I set UniformItemSizes to true)
>>>
>>> I tried QTableView and it is immediate.
>>> However the scrolling become slow if we are viewing the last elements.
>>>
>>> Please can someone give me some insights?
>>>
>>> Cheers,
>>> Sylvain
>>>
>>>     
>> I am having a very similar problem with a QTableView. Once the model is 
>> filled and the user is just moving around the table, just moving from 
>> one cell to the other, or moving the scroll bar, takes a lot of time. 
>> Each call to the data() method requires a search into the model to find 
>> the data, but the model only contains a few 10's of items, it is not 
>> large. Does anyone know where to look for ways to speed this up? Are 
>> there some optimization tricks?
>>   
> 
> I think the OP is asking the opposite question. How to make QListView
> perform as well as QTableView. QTableView in most cases is a  lot
> faster. A huge improvement can be gotten by setting
> setUniformItemSizes(). Of course to use that you need to make sure all
> your items have the same row size.
> 
> Good Luck!
> --Justin
Sorry I diverted the discussion a bit, but maybe my solution is somewhat 
relevant anyway. I could not use valgrind, I am working in Windows XP 
(did not post that info). Also, my model was not reading or writing to 
networks, it was working from a std::deque<> in memory. So, I put in 
some static counters to see how often data(), rowCount() get called, 
data() was called about 40 times and rowCount() > 130 times for each 
refresh of the table. But even that should not be excessive. So to debug 
a bit, I replaced data() with random number generator, and rowCount() 
with a constant, and voila! snappy refresh. So, I just optimized both 
rowCount() and data() -- previously I was building a list of all 
elements to be displayed in the table from the Model, now I just search 
more efficiently for the count of such, and for data(), the one element 
needed.

Result: snappy performance!



More information about the Qt-interest-old mailing list