Results 1 to 12 of 12

Thread: QFileDialog does not always return path - (bug?)

  1. #1
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default QFileDialog does not always return path - (bug?)

    hi,

    i just encountered a problem with QFileDialog. I use the static method "getExistingDirectory" to select a path, used in my software.
    If i open the filedialog and click "Choose" without really choosing a dir, the return value is an empty string.
    I would have been expected at least the path to the directory which has been showed, when opening the filedialog.
    What if a user is happy with the path suggested at opening the dialog and just clicks "Choose" - i just get an empty string and do not know what has been selected.
    I do not set a default path at opening the dialog yet. but doing so would not solve the problem.

    if i use the dialog to browse to a specific dir and select it - i get the path as return value. if i open the dialog again - the previously selected dir is shown. if i click "Choose" now, the return value is an empty string again.

    is this a bug? i do understand why "Cancel" returns an empty string, but "Choose" too?

    to clarify my problem:

    i am not able to investigate, if the user clicked "cancel" or if the user is satisfied with the path suggested at showing the filedialog and just clicked "choose"
    in both cases i just get an empty string.

    thnx, chris
    Last edited by wysota; 2nd October 2010 at 00:14.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QFileDialog does not always return path - (bug?)

    I'm not sure that bevaviour is a bug.

    Quoting the documentation:
    The dialog's working directory is set to dir, and the caption is set to caption. Either of these may be an empty string in which case the current directory and a default caption will be used respectively.
    So, you always set a directory, even if you leave it empty.
    If it is empty, it defaults to the current directory.

    If the return is empty, nothing changed

  3. #3
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog does not always return path - (bug?)

    Quote Originally Posted by tbscope View Post
    If the return is empty, nothing changed
    yes, this is my problem - because there are two possible reasons for an empty return:

    1) the user clicked "cancel"
    2) the user is satisfied with the initially selected directory and clicked "choose"

    in the latter case i have to proceed with my code and "install" a few things in the selected directory.
    so if i do not get a return i simply cannot decide if the user clicked "cancel" or "choose"

    i hope i did explain the problem somehow understandable ...

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QFileDialog does not always return path - (bug?)

    I understand what you mean, but I can't reproduce your problem here. Please could you show us the code your are exactly using. Maybe it is a problem with PyQt or whatever you use.

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog does not always return path - (bug?)

    Quote Originally Posted by thefriedc View Post
    so if i do not get a return i simply cannot decide if the user clicked "cancel" or "choose"
    QFileDialog is model, it returns whether the cancel or choose button is pressed...

  6. The following user says thank you to squidge for this useful post:

    thefriedc (1st October 2010)

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QFileDialog does not always return path - (bug?)

    On my Linux box if I pass an empty string as the dir argument then immediately press Choose it get the current working directory returned. If I pass a starting directory and immediately press Choose then I get that directory back. I only get an empty string return if the user presses Cancel.

    Which platform is displaying this problem? On Windows and Mac the native dialog is used and this might account for the difference.

  8. The following user says thank you to ChrisW67 for this useful post:

    thefriedc (1st October 2010)

  9. #7
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog does not always return path - (bug?)

    ah, great - this is good to know.

    i only tested it under osx. maybe there is really a difference because of using the native filedialog.

    thank you very much for this information

  10. #8
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog does not always return path - (bug?)

    Quote Originally Posted by squidge View Post
    QFileDialog is model, it returns whether the cancel or choose button is pressed...
    yes - i could create an instance of QFileDialog and then connect to the rejected() and accepted() signals (if this is what you mean)

    at the moment i just use a static method for displaying the filedialog which is really handy and just a one-liner. maybe i should really switch to the instance approach.

    thanks
    Last edited by thefriedc; 1st October 2010 at 09:32. Reason: forgot tu quote

  11. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog does not always return path - (bug?)

    No, I mean more like:

    Qt Code:
    1. QFileDialog dialog(this);
    2. if (dialog.exec())
    3. (... user has chosen OK ...)
    To copy to clipboard, switch view to plain text mode 

  12. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QFileDialog does not always return path - (bug?)

    Try the QFileDialog::DontUseNativeDialog option to test the theory.

  13. The following user says thank you to ChrisW67 for this useful post:

    thefriedc (3rd October 2010)

  14. #11
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog does not always return path - (bug?)

    Yes, it works, when setting "DontUseNativeDialog". I always get the current selected path when clicking "Choose".

    thanks a lot!

  15. #12
    Join Date
    Sep 2010
    Posts
    11
    Thanks
    3
    Qt products
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog does not always return path - (bug?)

    omg - i just investigated something "terrible"

    the native filechooser dialog returns the current path as well. there is just one difference, when directly choosing the suggested path - there is a trailing "/" at the path string.
    in my code i split the return value by "/" and take the last item. therefore i get an empty string as last item. i only checked this splitted value.

    im really sorry for this false alarm.

    chris

Similar Threads

  1. Replies: 6
    Last Post: 22nd April 2010, 15:43
  2. Replies: 1
    Last Post: 19th March 2010, 13:59
  3. Replies: 8
    Last Post: 17th October 2009, 08:10
  4. QFileDialog disable Dir Path
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 19:57
  5. The return of the king!
    By fullmetalcoder in forum Qt-based Software
    Replies: 56
    Last Post: 3rd September 2006, 01:38

Tags for this Thread

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.