QDirIterator repeating Dir
-
I'm trying to iterate through all the directories in a file structure. However I'm finding that QDirIterator is repeating, and I'm not sure why.
@
QString root = "/accounts/1000/";
QDirIterator it(root, QDir::Dirs | QDir::NoDot | QDir::NoSymLinks,
QDirIterator::Subdirectories);
while (it.hasNext()) {
qDebug() << it.filePath();
it.next();
}
@The output looks something like
Debug: "/accounts/1000/removable"
Debug: "/accounts/1000/removable/.."
Debug: "/accounts/1000/search"
Debug: "/accounts/1000/shared"
Debug: "/accounts/1000/shared/.."
Debug: "/accounts/1000/shared/voice/.."
Debug: "/accounts/1000/shared/protected_media"
Debug: "/accounts/1000/sharewith"
Debug: "/accounts/1000/sys"
Debug: "/accounts/1000/sysdata"
Debug: "/accounts/1000/appdata/sys.keyboard"
Debug: "/accounts/1000/appdata/sys.airservices"
Debug: "/accounts/1000/appdata/sys.navigator"
Debug: "/accounts/1000/shared"
Debug: "/accounts/1000/shared/.."The ones it repeats seem to be the ones it has permission to enter. How can I get it to not repeat directories and also not to display ".." and still recurse.
-
Add QDir::NoDotAndDotDot to your flags.
-
That got rid of the ".." but still the repeat directories still exist.
-
This is indeed strange, I don't know the reason for that. As a workaround, you can store the results in a QStringList and then call ::removeDuplicates().
-
I'm using it as an interator so removing Duplicates doesn't quite work.
I added the following to check for duplicates and it worked fine.
if (!Pathlist.contains(it.filePath())){
qDebug() << it.filePath();
Pathlist<<it.filePath();So is this some sort of bug in Qdiriterator then?
-
I have no idea, but certainly does not look like a design decision. I usually use ::entryInfoList myself, I don't remember this happening.
You can report the bug on "JIRA":http://qt-project.org/wiki/ReportingBugsInQt. If you choose to do it, please post a link to the bug here so that we can follow it.
-
Not sure whether this has anything to do with the problems you're experiencing, but you should call the qDebug() output after the it.next() call. (See Qt documentation about their java-style iterators.)