[Qt-interest] Slow QTreeWidget
Kenneth Beck
nekkceb at comcast.net
Wed Mar 25 04:07:31 CET 2009
Can someone tell me why my performance is so slow with this code? I am
filling a tree widget that has about 40+ columns, but only 14 rows. As
the table is filled with all 14 rows initially, the first row is added
quickly, but each subsequent row appears more and more slowly, as if the
code is updating previous rows for each new row. Here is the code for
adding a row:
void
ModMaxTestDlg::addResultRow(double elaps_mins, int rnr, int ct, double
*data)
{
QList<QTreeWidgetItem *> lvitems=moduleRsltList->findItems
(QString::number(rnr), Qt::MatchExactly,0);
QTreeWidgetItem *lvitem=0;
if (lvitems.count()>0)
lvitem= lvitems[0];
if (!lvitem)
{
lvitem= new QTreeWidgetItem(moduleRsltList);
lvitem->setData(0,Qt::DisplayRole,QString::number(rnr));
lvitem->setData(1,Qt::DisplayRole,
QString::number(elaps_mins,'f',2));
}
if (ct && (lvitem!=0))
{
int i;
for (i=1;i<=ct;i++)
lvitem->setText(i+1,QString::number(data[i-1],'f',6));
}
}
The addResultRow() gets called in a simple for-loop. I know the time
constraint is here, in the last for loop that calls lvitem->setText ct
times.
Qt 4.5.0, Windows XP, using Visual C++ 2003.
More information about the Qt-interest-old
mailing list