Results 1 to 3 of 3

Thread: QFileDialog getSaveFileName() doesn't convey choice to NOT OVERWRITE existing file

  1. #1
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question QFileDialog getSaveFileName() doesn't convey choice to NOT OVERWRITE existing file

    With the use of the static QFileDialog getSaveFileName() method -- if the file chosen by user already exists, the user is given the choice of not overwriting that file. (This is with Qt 4.3.3).



    However, there doesn't seem to be a way for the caller to know that the user made that choice (of aborting the save operation, being that the file already exists).

    When the user CANCELS the selection operation (before making the selection), an empty string is returned as the file path result. An empty string should probably also be the result in the case of the user overwrite denial. But it isn't. See code sample, below.

    Is there a well known global entity to check for this user response? Currently this is an unavoidable bug: the file gets overwritten regardless of the user's choice !!!

    Test code:
    Qt Code:
    1. ...
    2. static const QString caption ("Select Report Output File");
    3.  
    4. QString startPathStr = ... // details omitted
    5.  
    6. static QString selectedFilter ("");
    7. static const QString filter ("HTML (*.htm *.html);;"
    8. "TEXT (*.txt);;"
    9. "All (*)");
    10.  
    11. // **************************************************
    12. // *** Show and Execute Save File Path Selector ***
    13. // **************************************************
    14.  
    15. const QString userPickedPath =
    16. QFileDialog::getSaveFileName (NULL, // parent widget
    17. caption,
    18. startPathStr,
    19. filter,
    20. &selectedFilter);
    21.  
    22. const bool userPickedEmpty (userPickedPath.isEmpty());
    23.  
    24. std::cout << " Picked: '" << qPrintable (userPickedPath) << "' "
    25. << (userPickedEmpty ? "[EMPTY]" : "[GOOD TO GO]")
    26. << std::endl;
    27.  
    28. if (userPickedEmpty)
    29. {
    30. // File selection canceled by user.
    31. return (false);
    32. //----------->>
    33. }
    34.  
    35. setReportPath (userPickedPath);
    36. return (true);
    37. //---------->>
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance,
    Phil Weinstein, CADSWES
    http://cadswes.colorado.edu/
    Attached Images Attached Images
    Last edited by philw; 28th March 2009 at 09:32. Reason: formatting

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog getSaveFileName() doesn't convey choice to NOT OVERWRITE existing fil

    You can put the check yourself after you get the save file name ? cant you ?
    Also there might be so many cases, so its expected of the function to only return a file name, and not overwrite it

  3. #3
    Join Date
    Jun 2008
    Location
    Boulder, Colorado, USA
    Posts
    70
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog getSaveFileName() doesn't convey choice to NOT OVERWRITE existing fil

    Quote Originally Posted by aamer4yu View Post
    You can put the check yourself after you get the save file name ? cant you ?
    Also there might be so many cases, so its expected of the function to only return a file name, and not overwrite it
    Well, good idea. I can DISABLE the overwrite query popup that is automatically implemented by QFileDialog::getSaveFileName(). That can be done with the optional QFileDialog::Options parameter, bitmask value: QFileDialog:: DontConfirmOverwrite, and checking the existance of the selected file with QFileInfo, and showing my own confirmation dialog box if the file does exist. I guess I'll do that.

    But this REALLY IS a BUG (a design oversight, I think) in the Confirm-Overwrite feature of QFileDialog:: getSaveFileName(), -- enabled by default. It's a pretty bad bug because the file WILL be overwritten by the client code because -- if this is true -- the client code has no way of being informed of the user's choice to ABORT the write operation. Is this true?
    Last edited by philw; 28th March 2009 at 10:19. Reason: smiley showed up with scope operator followed by a D; and added a detail.

Similar Threads

  1. Replies: 4
    Last Post: 13th June 2007, 15:37

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.