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:
Code:
QString fileName
= dialog
->getSaveFileName
(0,dialog
->tr
("Save Logs"),
"myfile.zip",dialog
->tr
("Logs (*.zip);;All Files (*)"));
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 ?
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().
Re: QFileDialog getSaveFileName not showing the default filename on Fedora 33
Quote:
Originally Posted by
d_stranz
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.
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.