Results 1 to 5 of 5

Thread: Problem with QFileDialog::getOpenFileName()

  1. #1
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem with QFileDialog::getOpenFileName()

    Hi,
    in my app I let users select an image file with the following call:
    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName(this);
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with QFileDialog::getOpenFileName()

    Oh, does QFileDialog::getOpenFileName() let you choose a directory? Or do you mean QFileDialog::getExistingDirectory()?
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem with QFileDialog::getOpenFileName()

    Quote Originally Posted by spud View Post
    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.
    J-P Nurmi

  5. The following 2 users say thank you to jpn for this useful post:

    spud (1st November 2007), Tamara (20th November 2007)

  6. #5
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.