PDA

View Full Version : file name returned by QFileDialog::getSaveFileName()



Lexrst
20th June 2008, 02:40
Hello all, using Qt 4.3.3 and Open Suse 10.3

I'm trying to use the static function QFileDialog::getSaveFileName and I notice that the file name returned doesn't have the file extension that is specified in the selected filter appended to it. This renders the overwrite check useless as it's looking for the filename without an extenstion when the filename should have one.

Some code to illustrate:


QString fileName;
QString filter = tr("My Files (*.ggg)");

fileName = QFileDialog::getSaveFileName(this, tr("Dlg title"), tr("/home/temp/"), filter);
qDebug() << fileName;

now when this code is executed I would expect fileName to have a .ggg extenstion but it's only the path + the text the user entered in the lineEdit for the filename. So if the user didn't type in the extension (in this case .ggg) it's not included in the filename returned. The overwrite check is looking for the filename with no extenstion, so it doesn't complain. I've tried setting the selectedFilter in the function call and this makes no change in my result.

Am I doing something incorrectly or is this just how it works?
Obviously I can check the filename and add the extension, but I'd like to use the overwrite check so I don't have to close the dialog and reopen it just so the user can pick another name.

mcosta
20th June 2008, 09:03
QFileDialog::getSaveFileName() doesn't add extension to fileName this because you can select a "multiple extension filter".
For example



fileName = QFileDialog::getSaveFileName(this, tr("Open File"), "", tr("Image Files (*.png *.bmp *.jpg)"));


Then you ave to specify the extension

Lexrst
20th June 2008, 17:38
QFileDialog::getSaveFileName() doesn't add extension to fileName this because you can select a "multiple extension filter".

Then you have to specify the extension

Makes sense. Thanks.