PDA

View Full Version : Determining selected filter on getSaveFileName



Vash5556
14th May 2009, 17:34
I am currently wondering how you can determine which filter the user selected with using QFileDialog::getSaveFileName().

I currently have it written as so, and have no idea how to implement it. I saw something about QFileDialog::selectedNameFilter() but would have no idea how to implement.


bool VashTextEditor::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), QDir::homePath(),
tr("Vash Text Editor Files (*.vte);;Python (*.py);;C++ (*.cpp *.h *.cxx *.c)"));
if (fileName.isEmpty())
return false;

return saveFile(fileName);
}

any help would be greatly appreciated and thanks in advance.

Vash5556
14th May 2009, 21:18
I figured it out. It turns out all along I was misreading the documentation.

ulmly
23rd June 2009, 11:06
I have no problem with it under Mac OS X Leopard.

However under Linux, the problem occurs. The selectedFilter parameter does not return back what kind of filter the user choose.

Any idea ???? :confused:

ulmly
23rd June 2009, 11:08
At the moment I have to go around by calling no static functions.

ulmly
23rd June 2009, 19:21
Let me to make more clear about the problem.

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.