I have getSaveFileName with some filters, and I want one of them to be selected when the user opens the Save dialog. The Qt documentation reads as follows:
You can select the default filter by setting the selectedFilter parameter to the desired value.
I try the following option:
QString selFilter="All files (*.*)"; QFileDialog::getSaveFileName(this,"Save file",QDir::currentPath(), "Text files (*.txt);;All files (*.*)",&selFilter);
But when the dialog box appears, the Text Files filter is selected (in general, the first filter from the list). I also tried all of the following:
selFilter="All files"; selFilter="All files (*.*)\n"; selFilter="All files (*.*);;"; selFilter="All files (*.*)\0";
and various mixtures of these options. The format of the filter list in my code is in accordance with the documentation (example line from Qt docs):
"Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
Note that the output to the selFilter variable works correctly: after the user clicks OK, the selFilter variable contains a filter selected by the user.
Platform: Linux (OpenSUSE 12.1), Qt 4.7.4, gcc 4.6.2.
So how to set the default filter ?!
source share