1

如何将目录和子目录列表添加到 QStringList?

这就是我所拥有的...

QStringList dirList;

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

但我认为它不能正常工作,因为当我迭代列表时它没有显示所有文件夹,它会跳过其中的一些。

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

将目录和子目录添加到 QStringList 的正确方法是什么?

谢谢

4

1 回答 1

1

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.

于 2013-12-25T10:00:51.620 回答