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. Default file name for QFileDialog
QtWS25 Last Chance

Default file name for QFileDialog

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.6k 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.
  • M Offline
    M Offline
    Marcusdrl
    wrote on 22 Jun 2021, 14:04 last edited by
    #1

    Hello, is it possible to set a default file name for QFileDialog::getSaveFileName? So when the user click in the button to save the file it will come with a default name that is changeable.

    J 1 Reply Last reply 22 Jun 2021, 14:26
    0
    • M Marcusdrl
      22 Jun 2021, 14:04

      Hello, is it possible to set a default file name for QFileDialog::getSaveFileName? So when the user click in the button to save the file it will come with a default name that is changeable.

      J Offline
      J Offline
      JonB
      wrote on 22 Jun 2021, 14:26 last edited by
      #2

      @Marcusdrl
      Try as per the example at https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName

      The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected

      But I don't know if that indeed only works if the file already exists and so can be selected.

      M 1 Reply Last reply 22 Jun 2021, 16:12
      2
      • G Offline
        G Offline
        Gerd
        wrote on 22 Jun 2021, 14:31 last edited by
        #3

        From documentation:
        This is a convenience static function that will return a file name selected by the user. The file does not have to exist.

        J 1 Reply Last reply 22 Jun 2021, 15:09
        1
        • G Gerd
          22 Jun 2021, 14:31

          From documentation:
          This is a convenience static function that will return a file name selected by the user. The file does not have to exist.

          J Offline
          J Offline
          JonB
          wrote on 22 Jun 2021, 15:09 last edited by JonB
          #4

          @Gerd
          That only talks about whether the file to save to has to exist, or can be a new one. It does not say anything about whether if you supply a file path for the dir parameter which does not exist it will or will not copy the filename into the edit control for the user. Which is why I said the OP will need to test whether it does or not.

          1 Reply Last reply
          1
          • J JonB
            22 Jun 2021, 14:26

            @Marcusdrl
            Try as per the example at https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName

            The file dialog's working directory will be set to dir. If dir includes a file name, the file will be selected

            But I don't know if that indeed only works if the file already exists and so can be selected.

            M Offline
            M Offline
            Marcusdrl
            wrote on 22 Jun 2021, 16:12 last edited by
            #5

            @JonB thanks for the reply, it worked! I also used QStandPaths to set downloads location as default dir.

            But I don't know if that indeed only works if the file already exists and so can be selected.

            As @Gerd mentioned, the file doesnt have to exist.

            Anyway, ty for the replys!

            1 Reply Last reply
            0

            5/5

            22 Jun 2021, 16:12

            • Login

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