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 8 Jul 2022, 15:08 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.

    J 1 Reply Last reply 8 Jul 2022, 15:13
    0
    • D djsuson
      8 Jul 2022, 15:08

      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.

      J Offline
      J Offline
      JonB
      wrote on 8 Jul 2022, 15:13 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 10 Jul 2022, 02:09 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.

        J 1 Reply Last reply 10 Jul 2022, 07:36
        0
        • D djsuson
          10 Jul 2022, 02:09

          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.

          J Offline
          J Offline
          JonB
          wrote on 10 Jul 2022, 07:36 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 10 Jul 2022, 20:44
          2
          • J JonB
            10 Jul 2022, 07:36

            @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 10 Jul 2022, 20:44 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 10 Jul 2022, 21:07 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

              1/6

              8 Jul 2022, 15:08

              • Login

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