Results 1 to 11 of 11

Thread: get to know if click yes on replace warning dailog during getSaveFileName()

  1. #1
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default get to know if click yes on replace warning dailog during getSaveFileName()

    hi,
    when I use getSaveFileName(), it will launch save dialog and if I give any existing file name and try to save,
    it will lanunch replace warning dailog, here how can I know whether user clicked Yes/No .

    Thanks in advance .
    Last edited by prasad.ece2; 24th December 2013 at 11:27.

  2. #2
    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: get to know if click yes on replace warning dailog during getSaveFileName()

    You can't directly. If the user presses Yes then the dialog closes and the file name is returned, just the same as if the file did not exist when the user clicked Ok. If the user presses No the dialog does not close and the user can select another file name. If the user clicks Cancel the dialog closes and an empty string is returned.

    If you get a non empty string, and the file exists then the user must have clicked Yes when prompted.

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

    prasad.ece2 (27th December 2013)

  4. #3
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    could you please elaborate it, i am not able to get it properly...

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    If getSaveFileName() returns a non-empty string, i.e. a filename, then the user has either entered a new file name or OKed the overwriting of an existing file.
    So you can safely assume that it is OK to write to that file.

    Cheers,
    _

  6. #5
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    my requirement is I need to call certain function, only if file is overwritten, I have to ignore the case of creating new file.

  7. #6
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    in both cases, if file exist(& click on yes for replace warning dailog) or if file does not exists(&click on save) getSaveFileName() will return a non empty string only.. so how can we come to know that warning dailog appears and user clicked on yes. (i need the situation exactly warning dailog appears & user clicks on yes, I have to ignore the situation if file created first time) .

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    I don't see where you can possibly have any problem left.

    If the chosen file does not exist, then the user is not asked for overwrite.
    If the chosen file does exist, the user is asked and the filename is only returned if overwrite has been confirmed.

    So, by pure logicical deduction, the defining thing is the existance of the file, right?

    Cheers,
    _

  9. #8
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    in both cases, file exist or not exist, the return value of getSaveFileName() is not empty string only (i.e file name of newely created file/file name that was replaced).
    with this return value(file name) how can I say that this is the file got replace or this is the file newly created.

  10. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    with this return value(file name) how can I say that this is the file got replace or this is the file newly created
    You have a wrong assumption that this method is modifying the filesystem. It only returns path choosen by the user, it doesn't modify / create any files.

  11. The following user says thank you to stampede for this useful post:

    prasad.ece2 (27th December 2013)

  12. #10
    Join Date
    Jun 2013
    Location
    Bangalore
    Posts
    27
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    yes stampede, now I came to the mistake. thank you.

  13. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: get to know if click yes on replace warning dailog during getSaveFileName()

    So if you really need to know if the user chose to overwrite an existing file, then you can use QFileInfo::exists():

    Qt Code:
    1. QString fileName = QFileDialog::getOpenFileName( ... );
    2. if ( !fileName.isEmpty() )
    3. {
    4. QFileInfo fileInfo( fileName );
    5. if ( fileInfo.exists() )
    6. {
    7. // then the user chose an existing file
    8. }
    9. else
    10. {
    11. // the user chose to create a new file
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Telling apart single click and double click in QTableView
    By jgirlich in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2013, 14:27
  2. Replies: 2
    Last Post: 16th July 2012, 12:40
  3. Replies: 0
    Last Post: 20th February 2012, 12:52
  4. Replies: 1
    Last Post: 7th May 2011, 20:24
  5. Replies: 2
    Last Post: 11th January 2009, 23:24

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.