Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get overwrite result from QFileDialog
QtWS25 Last Chance

How to get overwrite result from QFileDialog

Scheduled Pinned Locked Moved Solved General and Desktop
qfiledialog
6 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    djsuson
    wrote on last edited by
    #1

    I have a save file function that uses the standard QFileDialog box to get the output file name. If the user selects a file that already exists, a query box pops up to confirm that the user wants to overwrite the selected file. However, I can't seem to find any way to get the results of that choice. I assume this is pretty simple and I'm missing something obvious, but I'm definitely missing it. Any help is appreciated.

    JonBJ 1 Reply Last reply
    0
    • D djsuson

      I have a save file function that uses the standard QFileDialog box to get the output file name. If the user selects a file that already exists, a query box pops up to confirm that the user wants to overwrite the selected file. However, I can't seem to find any way to get the results of that choice. I assume this is pretty simple and I'm missing something obvious, but I'm definitely missing it. Any help is appreciated.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @djsuson
      You don't/shouldn't get the result of this. It is internal to the Save Dialog. If the user picks an existing file to save to the dialog verifies with them that they want to overwrite. You can assume the dialog only returns the filepath to you if/when the user has confirmed.

      1 Reply Last reply
      2
      • D Offline
        D Offline
        djsuson
        wrote on last edited by
        #3

        That was what I needed to know. I combined this with QFileInfo to find out of the chosen file exists or is new. I need to modify the name for use with another library if I'm overwriting a previously existing file. Thank you for the help . I'll mark this as closed.

        JonBJ 1 Reply Last reply
        0
        • D djsuson

          That was what I needed to know. I combined this with QFileInfo to find out of the chosen file exists or is new. I need to modify the name for use with another library if I'm overwriting a previously existing file. Thank you for the help . I'll mark this as closed.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @djsuson
          That's OK, but your user is going to be presented with a rather odd/confusing/untrue prompt. If they pick an existing from your save dialog it will put up a message saying "Are you sure you want to overwrite this file?". They say "Yes", but in fact you then alter that filename to save to a different file and not overwrite the file they picked.

          If you want to be more "truthful" to the user you might consider setting the QFileDialog::Options you pass to getSaveFileName() to include

          QFileDialog::DontConfirmOverwrite Don't ask for confirmation if an existing file is selected. By default confirmation is requested.

          because you won't actually be overwriting the file they selected. You might also tell them if you amend their (existing) selected file to something else.

          D 1 Reply Last reply
          2
          • JonBJ JonB

            @djsuson
            That's OK, but your user is going to be presented with a rather odd/confusing/untrue prompt. If they pick an existing from your save dialog it will put up a message saying "Are you sure you want to overwrite this file?". They say "Yes", but in fact you then alter that filename to save to a different file and not overwrite the file they picked.

            If you want to be more "truthful" to the user you might consider setting the QFileDialog::Options you pass to getSaveFileName() to include

            QFileDialog::DontConfirmOverwrite Don't ask for confirmation if an existing file is selected. By default confirmation is requested.

            because you won't actually be overwriting the file they selected. You might also tell them if you amend their (existing) selected file to something else.

            D Offline
            D Offline
            djsuson
            wrote on last edited by
            #5

            @JonB no, it will overwrite the file. For some weird reason, the FITS library requires a ! in front of the file name to overwrite, otherwise it throws an error

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Just a recommendation: you should put a note in your code about that requirement otherwise there will likely be someone in the future (yourself included) that will wonder why there's that ! char there.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved