PDA

View Full Version : QListView and big database - bad performance



atomic
26th July 2014, 18:45
Hi,
I have problem with performance QListView.

For add items I used this function



void MainWindow::addToModel(const QString &path)
{
QStandardItem * item = new QStandardItem();
item->setIcon( icon );
item->setText( path );

dirModel.appendRow( item ); // QStandardItemModel

}


It work fine but when I try add 200 000 items my application froze for 3-4 seconds.

What I already done is



setUniformItemSizes( true );


What can I do to speed up this process?

anda_skoa
27th July 2014, 11:40
Maybe use QFileSystemModel?

Cheers,
_

d_stranz
29th July 2014, 05:14
Besides the fact that no one is going to look at a list view containing 200,000 items (Do you seriously think any user will do that? Would you?), the way you are appending to the model probably is causing (1) the model to resize itself frequently and (2) the list view to redraw itself (and maybe sort) with each new entry.

If you know in advance how many things you are adding, then set the rowCount() on the model first, then use setItem() instead of appendRow().

You could also create all of the QStandardItem instances, put them in a QList<> and add them all at once with insertColumn() or appendColumn(). Remember that with a QListView, you only get one column.