PDA

View Full Version : How to Display only external devices in QtFiledialog



vjsharma_30
18th February 2010, 16:15
Hi ,
I want to use the QFileDialog to display only the external devices conencted to the linux system.If i use
QFileDialog::getExistingDirectory(this,tr("File list"), QDir::currentPath());
it lists the file system of the computer also. I want to filter it and just show the list of external devices connected to the system like any USB connected should be shown in the dialog.
I tried using setFilter(QDir::Drives); also but i read about this that Linux ignores this. So is there any way so that in file dialog i can display ONLY the USB/external devices connected? so that i don't show the entire file system of the computer.

psih128
18th February 2010, 16:35
I dont think it is possible with the standard QFileDialog. I'm not sure but I believe that this class uses standard Windows file dialog on Windows, standard Mac file dialog on Macs, something alike on Linux. So it's limited to whatever is provided by the OS.

Most likely you will have to create your own dialog, or come up with a different solution.

vjsharma_30
18th February 2010, 17:55
But why QDir:: Drives doesn't work under linux?
I think there should be some way of putting the filters etc to achieve this.

psih128
18th February 2010, 18:36
QDir:: Drives 0x004 List disk drives (ignored under Unix).
Drives is a feature attributable to Windows only.

vjsharma_30
18th February 2010, 19:08
so there is no way out apart from creating a custom dialog of my own?

squidge
18th February 2010, 19:22
On Windows, each drive has a letter, so you have C: D: E: etc. Under Linux you have no such system. A device such as a USB key can appear at any point of the file system.

The best alternative you have is to parse the output of the 'df' command and create your own custom dialog, but it would be more intuitive to the user (and easier for you to code) to just show the entire file system and let them navigate themselves.

vjsharma_30
18th February 2010, 19:27
yes,you are right but i don't want user to play around with the terminal's file system. That was my idea. Also i don't know whether it is clear or not,i not only want to list the USB drives but also let the user browse through them,like normal file dialog.