PDA

View Full Version : QListView not displaying all directory files



been_1990
5th May 2009, 04:16
Im settings the QListView's index:


QString directory = "C:\\Users\\Username\\Desktop";
ui->list->setRootIndex(model.index(directory));


But it displays only 101 items as opposed to 143 showing on explorer.exe(I know, Im messy ....) Any idea as to why?

Update: I found out that the files not displayed are Windows shortcut files. Including Recycle Bin, My Computer & others.

mcosta
5th May 2009, 08:24
Try to set the model filter with QDirModel::setFilter()

wysota
5th May 2009, 08:35
It would be good to know how the model is setup and what is the actual model class.

been_1990
5th May 2009, 11:32
private:
QDirModel model;
Thats how I put it in my class.

faldzip
5th May 2009, 12:29
Did you try setting resolve symlinks to true ? QDirModel::setResolveSymlinks()?

been_1990
5th May 2009, 16:13
Tried both :

model.setFilter(QDir::AllEntries);
model.setResolveSymlinks(true);

Still the same. Some shorcuts appear but others dont, missing 30 or more files...

fifth
5th May 2009, 18:34
Im settings the QListView's index:


QString directory = "C:\\Users\\Username\\Desktop";
ui->list->setRootIndex(model.index(directory));


But it displays only 101 items as opposed to 143 showing on explorer.exe(I know, Im messy ....) Any idea as to why?

Update: I found out that the files not displayed are Windows shortcut files. Including Recycle Bin, My Computer & others.

iirc from my windows days (been quite a few years) items such as Recycle Bin, My computer, etc are not items in the file system. I think the terminology is Windows Shell NameSpace, but googling should give you some code to work with.

You'll need to create a model to traverse the NameSpace using the Windows api.

wysota
5th May 2009, 20:21
I'd try QFileSystemModel first.

been_1990
6th May 2009, 02:55
Current code:

QFileSystemModel model;
QString directory = "C:\\Users\\Username\\temp files\\";
ui->list->setRootIndex(model.setRootPath(directory));
In this directory I have 69 Windows shortcuts. But my QListView shows only 68 . And if I doube the amount I am missing 2 shortcuts.
Im using Vista, could be the cause? Probably not...

wysota
6th May 2009, 08:35
What exactly is missing?

been_1990
6th May 2009, 13:45
I checked each file and the ones not shown where Recycle Bin, PGP Shredder and shortcut, "Vista Shortcut Manager" shortcut and SUPER © Uninstall shortcut. Apparently it doesn't show some shortcuts, I checked their properties and apparently they had no difference.
When pointed to my Pictures folder it doesnt show "Sample Pictures" shortcut. So it probably is a Windows-managed-shorcut problem.

fifth
6th May 2009, 16:52
I checked each file and the ones not shown where Recycle Bin, PGP Shredder and shortcut, "Vista Shortcut Manager" shortcut and SUPER © Uninstall shortcut. Apparently it doesn't show some shortcuts, I checked their properties and apparently they had no difference.
When pointed to my Pictures folder it doesnt show "Sample Pictures" shortcut. So it probably is a Windows-managed-shorcut problem.

You still need to use the Shell Namespace API if you want these "folders" on windows;

http://msdn.microsoft.com/en-us/library/cc144090(VS.85).aspx

A quick search came up this (http://bcbjournal.org/articles/vol4/0001/Enumerating_the_shell_namespace.htm) which gives a C++ example.

been_1990
7th May 2009, 12:50
So.. thats really the only way? I didnt quite understand how to pass that to QT. I get quite confused reading MSDN documentation.It would be better if there were a QT way..

wysota
7th May 2009, 14:26
The thing is that this is out of scope of the model. Those icons are not in the filesystem, they are fake icons created on the fly by Windows Explorer (or actually the Windows desktop probably). The model, on the other hand, contains contents of the file system.

been_1990
8th May 2009, 01:00
Okay. Thats understood. So the Recycle Bin and PGP Shredder appear at startup. They are "fake" icons. But what about the "Vista Shortcut Manager" shortcut and SUPER © Uninstall shortcut not appearing? They are not made on the fly and are a true "file".