How to add a list of directories and subdirectories to a QStringList?

505 views Asked by At

How can I add a list of directories and subdirectories to a QStringList?

This is what I have...

QStringList dirList;

QDirIterator iterateFolders("/Users/userName/targetFolder", QDir::Dirs, QDirIterator::Subdirectories);
while (iterateFolders.hasNext())
{
    dirList.append(iterateFolders.next());
}

But I don't think it is working correctly because when I iterate though the list it doesn't show all of the folders, it skips some of them.

for(int i=0; i<dirList.length(); i++)
{
    qDebug() <<" Dir At: " << dirList.at(i);
}

What is the correct way to add directories and subdirectories to a QStringList?

Thanks

1

There are 1 answers

0
László Papp On BEST ANSWER

What is the correct way to add directories and subdirectories to a QStringList?

What you wrote is correct.

As it seems you have now fixed the issue, we can only say that the error was in a different place of your code, but not with for and while being in the same function or method per se. If they are sequential, i.e. the for loop followed the while loop, it should been fine since by the point of printing, you accumulated all the paths you are interested in.