PDA

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



ulmly
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("QFileDialog::getSaveFileName()"),
saveFileNameLabel->text(),
tr("All Files (*);;Text Files (*.txt)"),
&selectedFilter,
options);

if (!fileName.isEmpty())
saveFileNameLabel->setText(fileName);
}


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.

wysota
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,
"QFileDialog::getSaveFileName()",
"",
QString("All Files (*);;Text Files (*.txt)"),
&selectedFilter);
qDebug() << fileName;
qDebug() << selectedFilter;

}


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

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

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

ulmly
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 :(

Piskvorkar
17th September 2009, 16:41
Hi!
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());
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setNameFilters(formats);

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

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