You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

prazak

Beginner

  • "prazak" started this thread

Posts: 27

Location: seattle, USA

  • Send private message

1

Tuesday, September 6th 2005, 5:46pm

SLOW...QT4 QTreeWidget vs QT3 QListView

Hello,

I have discovered what appears to me to be a show-stopping problem in my efforts to port to QT4.

My QT3 application uses a QListView to store several thousand multi-columned items. Data is stored in the list itself. The time it takes to build and display this list is just a few seconds. The list is very important to my application.

Then I ported to QT4...

I initially used the port of QListView which is Q3ListView. My code which worked so well previously now took very long to build the list. When I say very long I am talking like 10x as long, maybe more. I reasoned that perhaps Q3ListView, which is a support class for backwards compatability, was not optimized very well. So I looked for the perferred class to use instead and QTreeWidget seemed to fit the bill. I spent the time porting to this new class (very confusing as compared to QT3 version), but the slowness was still there.

I wonder if it has to do with the way I have to add new items in QT4 like so:

Source code

1
2
3
4
5
6
7
8
QTreeWidgetItem*item = new QTreeWidgetItem(list);
item->setText(0, "Insert"); 
item->setText(1, "New"); 
item->setText(2, "Items"); 
item->setText(3, "Like "); 
item->setText(4, "This"); 
item->setText(5, "into"); 
item->setText(6, "List"); 


In QT3 i could set those same 7 columns of data using the constructor of the QTreeWidgetItem equivalent which is QListViewItem. That mechanism does not appear to be available in QT4? Maybe that does not have anything to do with the difference in speed.

Any ideas on how to build and display a multi-column list that contains say 10000 rows in QT4 and be as fast as QT3 was?

prazak

Beginner

  • "prazak" started this thread

Posts: 27

Location: seattle, USA

  • Send private message

2

Tuesday, September 6th 2005, 8:39pm

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

I am confused. The standalone works fine. There must be some side effect in my real program I am not seeing. Could be nothing to do with the QTreeWidget. ?(

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <qapplication.h>
#include <qtreewidget.h>
#include <qstringlist.h>

int main(int argc, char **argv)
{
QApplication a(argc, argv);
QTreeWidget *_list = new QTreeWidget(0);
		
QStringList columns;
for(unsigned int col = 0; col < 7; col++)
     columns.append( QString("Column %1").arg(col) );	
_list->setColumnCount(columns.count());
_list->setHeaderLabels(columns);
_list->setAlternatingRowColors(true);

// Add 10000 lines
for(int i = 0; i<10000; i++)
{
QTreeWidgetItem*item = new QTreeWidgetItem(list);
item->setText(0, "Insert"); 
item->setText(1, "New"); 
item->setText(2, "Items"); 
item->setText(3, "Like "); 
item->setText(4, "This"); 
item->setText(5, "into"); 
item->setText(6, "List"); 
}
_list->show();

return a.exec();
}

dimitri

Professional

  • "dimitri" is male

Posts: 1,311

Occupation: Engineer

  • Send private message

3

Tuesday, September 6th 2005, 9:24pm

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

In such cases it's a good idea to run your program in a profiler and find where it spends most of its time. If you've never used a profiler before, I think it's a wise investment learning to use one.

I'm not saying there is necessarily a problem with your program here, it could indeed be a problem with Qt, but in any case the profiler may help understand the problem.

prazak

Beginner

  • "prazak" started this thread

Posts: 27

Location: seattle, USA

  • Send private message

4

Tuesday, September 6th 2005, 11:36pm

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

I ran Rational Quantify against the part of my app that is building the list and is very slow using QT4...

In the attached image, I sorted by F+D time. My function which adds items to the list is called Query::UpdateListFunction. It would appear that an inordinate amount of time is spent doing something with the list's vertical scroll bar? All this updatelistfunction does is add a single list item, nearly identical to the code above.

Perhaps I need to add some code to disable GUI updates or such until the whole list is constructed? That would prevent all the time spent resizing the vertical scroll bar.

Please advise, dimitri.
prazak has attached the following file:

chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

5

Wednesday, September 7th 2005, 1:51am

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

Did you try _list->setUpdatesEnabled(false);
I have enough sense to know that "common sense" is an oxymoron.

prazak

Beginner

  • "prazak" started this thread

Posts: 27

Location: seattle, USA

  • Send private message

6

Wednesday, September 7th 2005, 2:36am

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

Quoted

Originally posted by chickenblood
Did you try _list->setUpdatesEnabled(false);


Yes. I had this list working great with QT3, so I had all those kinds of tricks employed already. In QT3 I found that this trick helped me--it does not anymore in QT4. I think there must be a new version of this same "setUpdatesEnabled" that I do not know about and need to use to get my speed up.

chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

7

Wednesday, September 7th 2005, 6:33pm

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

Did you try _list->scheduleDelayedItemsLayout();
I have enough sense to know that "common sense" is an oxymoron.

prazak

Beginner

  • "prazak" started this thread

Posts: 27

Location: seattle, USA

  • Send private message

8

Wednesday, September 7th 2005, 9:37pm

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

Quoted

Originally posted by chickenblood
Did you try _list->scheduleDelayedItemsLayout();


I did after you suggested it. It sounds like it is what I want, however, it is protected which makes me think it is not to be used for this purpose.

error C2248: 'QAbstractItemView::scheduleDelayedItemsLayout' : cannot access protected member declared in class 'QAbstractItemView'

chickenblood

Professional

Posts: 657

Location: Mountain View, CA

Occupation: Data Monkey

  • Send private message

9

Wednesday, September 7th 2005, 10:48pm

RE: SLOW...QT4 QTreeWidget vs QT3 QListView

Oops, my mistake. Sorry.
I have enough sense to know that "common sense" is an oxymoron.