View Full Version : selectedFilter of getSaveFileName() gives nothing under Linux

24th June 2009, 11:58
Please look at the standarddialog of Qt4's Examples and Demos, exactly in the dialog.cpp. Here is the code I mean.

void Dialog::setSaveFileName()
QFileDialog::Options options;
if (!native->isChecked())
options |= QFileDialog::DontUseNativeDialog;
QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(this,
tr("All Files (*);;Text Files (*.txt)"),

if (!fileName.isEmpty())

The problem lies on the parameter selectedFilter which is not returning the user selected filter.

What makes me wonder is that the problem occurs only in Linux OS, but not in Mac OS X. I don't know what happens in MS Windows.

In my case, I need the user selected filter in order to save the file correctly.

Such a problem does not occur if I use QFileDialog as a regular class without calling the static function. However, it is nice if I could use the static function also.

Any kind of helps would be highly appreciated.

Thx in advance.

24th June 2009, 15:11
Works perfectly fine for me on Linux with Qt 4.5.1...

#include <QtGui>
#include <QtDebug>

int main(int argc, char **argv){
QApplication app(argc, argv);
QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(0,
QString("All Files (*);;Text Files (*.txt)"),
qDebug() << fileName;
qDebug() << selectedFilter;


$ ./x
"Text Files (*.txt)"

25th June 2009, 10:15
Do you think that it was a bug on Qt 4.5.0 and has been fixed on Qt 4.5.1 ?

Well, I should upgrade firstly to Qt 4.5.1 and then see what happens.

25th June 2009, 12:46
I don't think there was such a bug. A lot of software would be broken if that was the case.

26th June 2009, 07:33
I have tried with Qt 4.5.2 (the newest version coming yesterday) and such a problem doesn't occur.

I tried back to use Qt 4.5.0, and the problem came up again.

Not a bug ? if so, I don't know how to call such a problem :(

17th September 2009, 16:41
I had same problem today, i think it's realy bug ;-). I rather solve it by another way (not completly same, but functional):

QFileDialog dialog(this, tr("Save as ..."), editor->getFileName());

if (dialog.exec() != QDialog::Accepted) return false;

filter = dialog.selectedNameFilter();
fn = dialog.selectedFiles()[0];