PDA

View Full Version : Iterating with QDirIterator seems slow



TheShow
5th January 2010, 22:47
I'm using QDirIterator to find all subdirectories based on a name filter like this:



QStringList nameFilters;
nameFilters << "*CAL*";
QDirIterator dirIterator(path, nameFilters, QDir::Dirs, QDirIterator::Subdirectories);
QStringList results;
while (dirIterator.hasNext())
{
QString qstr = dirIterator.next();
results << qstr;
}

The path value is a directory that in this case contains over 30,000 files and 1,100 subdirectories. The code returns the correct result, but it is slow (5 seconds or more). It is interesting that the QDirIterator constructor above returns almost immediately, but the next() call within the loop is what takes so long. Is there any reason why this operation would take this long? There are less than 10 directories out of 1,100 that match the name filter, but it takes a long time just to iterate through them.

TheShow
6th January 2010, 16:55
As a test, I ran the dos command:

dir *CAL* /AD /S /B

on the same directory and it was extremely fast in returning the desired result.


Is there any Qt class that can provide this result with similar performance? This is a difference of a fraction of a second versus several seconds.