Issue using QDir/QDirIterator
Can someone tell me what is wrong with this code? It compiles fine, but I can’t seem to figure out how to set a directory.
Code:
#include <QtCore/QDir>
#include <QtCore/QDirIterator>
#include <iostream>
using namespace std;
void someFunction()
{
QDirIterator iter(path);
if(iter.fileInfo().exists() || iter.fileInfo().isDir() || iter.fileInfo().isFile())
cout << iter.filePath().toStdString();
else
cout << "failed\n";
}
int main()
{
someFunction();
getchar();
return 0;
}
It prints “failed†every time. What am I doing wrong?
Re: Issue using QDir/QDirIterator
From the QDirIterator docs:
Quote:
After construction, the iterator is located before the first directory entry.
Re: Issue using QDir/QDirIterator
Thanks. While testing I found that iter.hasNext() evaluated to true, so i tried iter.next() before the if/else block and it still prints "failed". Any ideas?
Re: Issue using QDir/QDirIterator
Works fine here:
Code:
QDirIterator iter(path);
iter.next();
if(iter.fileInfo().exists() || iter.fileInfo().isDir() || iter.fileInfo().isFile())
qDebug() << iter.filePath();
else
qDebug() << "failed\n";
Outputs: "/var/spool/cron"
Re: Issue using QDir/QDirIterator
Ah, I found my problem. Thanks!