Results 1 to 4 of 4

Thread: QFileDialog getSaveFileName not showing the default filename on Fedora 33

  1. #1
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QFileDialog getSaveFileName not showing the default filename on Fedora 33

    Hello,

    I'm working on a Qt application and need to show a file dialog for user to save a file. To make it convenient for the user, i need to show a default filename when the file dialog opens so the user just have to click on save and the file will be saved.
    This is the code block:

    Qt Code:
    1. QFileDialog *dialog;
    2. dialog = new QFileDialog;
    3. QString fileName = dialog->getSaveFileName(0,dialog->tr("Save Logs"),"myfile.zip",dialog->tr("Logs (*.zip);;All Files (*)"));
    To copy to clipboard, switch view to plain text mode 

    When the dialog opens, the filename box is blank there instead it should contain "myfile.zip" as filename.

    Also, note that this same function is working on Ubuntu 20.04 and not on Fedora 33.
    For Ubuntu 20.04 I'm using Qt : Qt Creator 4.11.1 Based on Qt 5.14.1
    For Fedora 33: Qt Creator 4.13.2 Based on Qt 5.15.2


    I'm guessing the version difference between Qt creator might have caused this issue. But i dont know what changed in the getSaveFileName() function. Could anyone please help ?
    Last edited by d_stranz; 26th April 2021 at 16:26. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,021
    Thanks
    280
    Thanked 817 Times in 806 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QFileDialog getSaveFileName not showing the default filename on Fedora 33

    The third argument to QFileDialog::getSaveFileName() is a -directory- not a -file- name. If you want to pre-select a file name, then you will have to use the non-static methods and call the QFileDialog::selectFile() method before calling QFileDialog::exec().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    Deeksha (26th April 2021)

  4. #3
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFileDialog getSaveFileName not showing the default filename on Fedora 33

    Quote Originally Posted by d_stranz View Post
    The third argument to QFileDialog::getSaveFileName() is a -directory- not a -file- name. If you want to pre-select a file name, then you will have to use the non-static methods and call the QFileDialog::selectFile() method before calling QFileDialog::exec().
    Hi, thanks for replying!

    The Qt documentation says:
    If dir includes a file name, the file will be selected.
    and it's working for ubuntu. Also, I have tried using selectFile() as well. It's not working either.

  5. #4
    Join Date
    Apr 2021
    Posts
    7
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QFileDialog getSaveFileName not showing the default filename on Fedora 33

    Found that if the file already exists then it's able to show the filename on the file dialog for Fedora 33.

Similar Threads

  1. QInputDialog like QFileDialog::getSaveFileName
    By BIllNo123 in forum Newbie
    Replies: 5
    Last Post: 23rd September 2010, 14:51
  2. problem with QFileDialog::getSaveFileName
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2009, 07:38
  3. A question about QFileDialog::getSaveFileName
    By Ali in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 19:46
  4. QFileDialog::getSaveFileName default extension
    By elcuco in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2007, 20:13
  5. QFileDialog::getSaveFileName issues with filename
    By dugs in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2006, 17:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.