You need to use the 5th optional line
I usually do it like this:
#define JPEG_FILES "JPG files (*.jpg)" #define BMP_FILES "BMP files (*.bmp)" #define PNG_FILES "PNG files (*.png)" QString selectedFilter; QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), "/home/user/MyDocs/", JPEG_FILES ";;" BMP_FILES ";;" PNG_FILES, &selectedFilter); if (fileName.isNull()) return; if (selectedFilter == JPEG_FILES) { ... } else if (selectedFilter == BMP_FILES) { ... } else if (selectedFilter == PNG_FILES) { ... } else {
The compiler will take care of the concatenation of the literals in the argument.
I'm not sure how the returned string interacts with tr() . You will have to check and find out. probably need to translate it. It would be better if the function returned the index of the selected filter, but, alas, this is not so.
It would be best to put the filters in the list, create a string from it, and then compare those listed in the list with the returned selected filter string. This also solves the tr() problem.
shoosh
source share