Bug 387481

Summary: Save file dialog doesn't return selected filter properly
Product: [Frameworks and Libraries] frameworks-kio Reporter: Alexander <ashaduri>
Component: Open/save dialogsAssignee: KIO Bugs <kio-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: benito, kdelibs-bugs-null, nate
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Alexander 2017-11-30 21:18:21 UTC
I'm using plain Qt5 applications and since I'm running Plasma, KDE dialogs  automatically replace Qt's built-in dialogs.

The problem is with the Save dialog (QFileDialog::getSaveFileName()).
If the "filter" parameter contains 2 filters with the same extensions, the "selectedFilter" parameter is always set to the first one, no matter which one the user selected.

Example code:
--------------------------
QString selectedFilter;
QString fileName = QFileDialog::getSaveFileName(this,
      "QFileDialog::getSaveFileName()",
      "hello.txt",
      "All Files (*);;UTF-16 Files (*.txt);;UTF-8 Files (*.txt)",
      &selectedFilter);
qWarning() << "selectedFilter: " << selectedFilter;
--------------------------

If the user selects "UTF-8 Files (*.txt)", "UTF-16 Files (*.txt)" is printed instead.

Qt's built-in dialog don't have this problem.

Thanks
Comment 1 Benito van der Zander 2018-05-10 16:44:34 UTC
I have a similar problem. The KDE file dialog always choose the first extension filter, but apparently also  when the extensions are different.


When you save a webpage in Firefox, you can choose to save it as "webpage  complete"  or "webpage html only", and it always choose the first entry in the list "webpage complete". Firefox had an option to use their own xul dialog rather than the kde dialog, but it seems they have removed that option.

Then in TeXstudio you can save a file as .tex file or with another file extension (e.g. plaintext (*.txt) or all files (*)), but the QFileDialog  always switches back to .tex files when saving another file. Only the QFileDialog::DontUseNativeDialog fixes this.