View Full Version : Simple Question on getExistingDirectory

2nd March 2006, 15:21
I'm implement a QFileDialog::getExistingDirectory() over a click of a button ......

but the ExistingDirectory is showing me all the directories including the CD-ROM and the
Maped-Drives .......

I have Two Maped_Drives ,CD-ROM and CD-Writer on my system .....

but i dont want these to displayed when I click that button.......

Is there any way i can filter some of the existing Drives on my System

Could Anyone Help

Thanks in Adv

2nd March 2006, 20:00
I think getOpenFileNames() is more what you are looking for.

2nd March 2006, 20:31
Unfortunately it doesn't seem to be possible to filter certain drive types.

2nd March 2006, 20:34
Well, you can overload it, and build in that logic for filterinf drive types.
But I am not sure how can know what type is a given drive...

2nd March 2006, 22:13
After taking a look at QFileDialog sources, basically one would have to write it's own
dialog for this kind of behaviour. Subclassing does not help much in this case..

But anyway, yes, the problem might be detecting drive types and probably needs using of platform dependant APIs.
Let me assume this is a windows environment, so for example you could try using GetDriveType (http://msdn.microsoft.com/library/en-us/fileio/fs/getdrivetype.asp?).

It could even be quite simple to implement that kind of dir selection dialog for windows.
Basically you could try subclassing QDirModel and remove/hide model indexes belonging to other than DRIVE_FIXED type drives.
Then just show the model in a tree view, dunno if it's really as simple as it sounds.. :)

3rd March 2006, 06:14
I'm sorry --what i meant was ---- i have a button which when clicked ---shows me the directory structure........

This I doing by a simple Signal and Slot method like this

connect(button,SIGNAL(clicked()),this,SLOT(button_ Clicked()));

I'm not implementing or overloading anything.....

yes the Operating System is Windows XP....

Could u explain what this "subclassing QDirModel and remove/hide model indexes " is

Could u give me few more opinions


3rd March 2006, 10:44
Yes I understood that you're launching the dialog for directory selection upon that button click. QFileDialog simply does not bow to your wishes when it comes to filtering out certain drive types or so. And there doesn't seem to be a way to add that behaviour by subclassing QFileDialog either.

Qt doesn't provide any way to check drive types. But alright, the environment has been outlined to windows, which offers a way to do that, as I mentioned in the earlier post. QDirModel provides a data model for the filesystem. It is extremely easy to just display filesystem contents in a tree by using QTreeView+QDirModel (QFileDialog uses QDirModel too, internally).

Here's a tiny example for showing directories of fixed hard drives. Examine and understand the code. All you need to do is to create a dialog with appropriate buttons and the example tree..