selectedFilter of getSaveFileName() gives nothing under Linux
Please look at the standarddialog of Qt4's Examples and Demos, exactly in the dialog.cpp. Here is the code I mean.
Code:
void Dialog::setSaveFileName()
{
if (!native->isChecked())
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.
Re: selectedFilter of getSaveFileName() gives nothing under Linux
Works perfectly fine for me on Linux with Qt 4.5.1...
Code:
#include <QtGui>
#include <QtDebug>
int main(int argc, char **argv){
"QFileDialog::getSaveFileName()",
"",
QString("All Files (*);;Text Files (*.txt)"),
&selectedFilter);
qDebug() << fileName;
qDebug() << selectedFilter;
}
Quote:
$ ./x
"/tmp/xxx.txt"
"Text Files (*.txt)"
Re: selectedFilter of getSaveFileName() gives nothing under Linux
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.
Re: selectedFilter of getSaveFileName() gives nothing under Linux
I don't think there was such a bug. A lot of software would be broken if that was the case.
Re: selectedFilter of getSaveFileName() gives nothing under Linux
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 :(
Re: selectedFilter of getSaveFileName() gives nothing under Linux
Hi!
I had same problem today, i think it's realy bug ;-). I rather solve it by another way (not completly same, but functional):
Code:
QFileDialog dialog
(this, tr
("Save as ..."), editor
->getFileName
());
dialog.setNameFilters(formats);
if (dialog.
exec() != QDialog::Accepted) return false;
filter = dialog.selectedNameFilter();
fn = dialog.selectedFiles()[0];