Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Default file name for QFileDialog



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



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



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



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



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


Log in to reply