Question

I'm starting to use QT, and trying QDir I copy the example in the references of QT the one which listing the content of a folder.

I'm trying to listing the content of the root path in a MacOS snow leopard, version of QT 5.1.1 But don't appear all of it :S

This is the code:

QFileInfoList list = QDir::root().entryInfoList();
for(int i=0; i<list.count(); i++){
    cout<< list[i].fileName().toStdString()<<endl;
}

But the output of this program is:

.
..
Applications
Developer
Library
opt
sockets.log
System
Users

When I think it should be: I know that ls -l don't show . and .. my worry is about the other folders, I put a line break separating the folders that appears in the output and ones who don't.

$ ls -l /
drwxrwxr-x+ 63 root    admin      2142 Sep 18 21:22 Applications
drwxrwxr-x@ 15 root    admin       510 Jan  1  2012 Developer
drwxrwxr-t+ 63 root    admin      2142 Sep 16 13:05 Library
drwxr-xr-x   3 root    admin       102 Jul 23 02:45 opt
-rw-rw-rw-   1 Andreu  admin        75 Sep 19 12:35 sockets.log
drwxr-xr-x   4 root    wheel       136 Sep 15 20:49 System
drwxr-xr-x   5 root    admin       170 Sep 15 20:17 Users

drwxr-xr-x@  2 root    wheel        68 Jun 23  2009 Network
drwxrwxrwt@  5 root    admin       170 Sep 16 14:01 Volumes
drwxr-xr-x@ 39 root    wheel      1326 Sep 15 22:46 bin
drwxrwxr-t@  2 root    admin        68 Jun 23  2009 cores
dr-xr-xr-x   3 root    wheel      4272 Sep 16 13:26 dev
lrwxr-xr-x@  1 root    wheel        11 Sep 15 20:04 etc -> private/etc
dr-xr-xr-x   2 root    wheel         1 Sep 16 13:26 home
-rw-r--r--@  1 root    wheel  20828964 Jun  8  2011 mach_kernel
dr-xr-xr-x   2 root    wheel         1 Sep 16 13:26 net
drwxr-xr-x@  6 root    wheel       204 Sep 15 20:08 private
drwxr-xr-x@ 67 root    wheel      2278 Sep 15 22:46 sbin
lrwxr-xr-x@  1 root    wheel        11 Sep 15 20:04 tmp -> private/tmp
drwxr-xr-x@ 14 root    wheel       476 Sep 16 13:07 usr
lrwxr-xr-x@  1 root    wheel        11 Sep 15 20:04 var -> private/var

Anyone can tell me why the other folders not appear?

Thanks :)

Was it helpful?

Solution

Add filter to entryInfoList

On Unix entryInfoList() does not list hidden files. You have to "ask" for them. I think it will be similiar on Mac.

QFileInfoList list = QDir::root().entryInfoList(QDir::AllEntries | QDir::System | QDir::Hidden);
for(int i=0; i<list.count(); i++){
    cout<< list[i].fileName().toStdString()<<endl;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top