Issue using QDir/QDirIterator (Qt 4.7.4)

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <QtCore/QDir>
#include <QtCore/QDirIterator>
#include <iostream>
 
using namespace std;
 
void someFunction()
{
    QString path = "C:/Users/";
    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?
Maybe you don't have access rights or something?
The same code works in Boost::filesystem, but doesn't integrate easily into the application I need this for which was built using Qt.

All I'm really trying to do is set a path and then print that path. Is there something else I need to do for it to work in Qt?
Topic archived. No new replies allowed.