Problem with QFileDialog::getOpenFileName()
Hi,
in my app I let users select an image file with the following call:
The problem is on Windows when I select the folder "Sample Images" in "My Pictures", instead of opening the folder, the function returns "xxx.lnk".
I know the folder is just a shortcut, but since I haven't specified "DontResolveSymlinks" I don't know why this happens.
I tried adding "DontUseNativeDialog" as a workaround, and the Qt dialog managed to open the folder, but when I select a file it complains "File not found".
I'm not sure what I'm doing wrong. Qt Designer is able to follow those shortcut just fine.
Re: Problem with QFileDialog::getOpenFileName()
Oh, does QFileDialog::getOpenFileName() let you choose a directory? Or do you mean QFileDialog::getExistingDirectory()?
Re: Problem with QFileDialog::getOpenFileName()
I don't want to choose a directory, but I have to double click them to navigate within the dialog.
Re: Problem with QFileDialog::getOpenFileName()
Quote:
Originally Posted by
spud
Qt Designer is able to follow those shortcut just fine.
Aha, now I realize the problem:
- with filter "Designer UI files (*.ui)" one can follow "Sample Images" shortcut because it's not acceptable file type
- with filter "All Files (*)" one can't follow "Sample Images" shortcut because it's acceptable file type
So, basically the problem is with Windows file dialog since it treats a directory shortcut as a file... right? You could work this around with QFileInfo::isSymLink() and QFileInfo::sysLinkTarget(). However, I'd suggest constructing a filter from QImageReader::supportedImageFormats(). First of all, it solves the problem and secondly, the user will be able to choose only supported image types. ;)
Re: Problem with QFileDialog::getOpenFileName()
You're exactly right. Thanks for clearing up exactly why this happens! I found out that this is a bug which is set to Fixed in 4.3.3. so for now I'll just ignore it.
I do pass on QImageReader::supportedImageFormats(), but it's good custom to provide the option "All files(*.*)". Even designer does it.;)