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

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 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.

    JonBJ 1 Reply Last reply
    0
    • M Marcusdrl

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      2
      • G Offline
        G Offline
        Gerd
        wrote on 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.

        JonBJ 1 Reply Last reply
        1
        • G Gerd

          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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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
          • JonBJ JonB

            @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 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

            • Login

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