Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-105483

QFileDialog adds wrong extension when All Files is selected as a filter when saving file in Windows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 5.15.2, 6.2.0
    • None
    • Windows

    Description

      When I open a QFileDialog for saving the file and select the filter to be ALL Files, ideally I would have expected no extension to be appended to the saved files, however, the extension of the first filter in the list is appended to the file while saving it.  I have attached a sample code to reproduce the same. The selected file in the code has .png appended to it when "All Files" is selected as a filter

      #include <QApplication>
      #include <QFileDialog>
      #include <QString>
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          QFileDialog fd;
          QStringList filter = {"Image files{png} (*.png)","Text files (*.txt)","Any files (*)"};
          fd.setNameFilters(filter);    
          fd.setOptions(QFileDialog::HideNameFilterDetails);
          fd.setAcceptMode(QFileDialog::AcceptSave);   
          if (fd.exec()) {        
              auto selectedFilter = fd.selectedNameFilter();        
              auto namefilters = fd.nameFilters();        
              auto fileSel = fd.selectedFiles()[0];   
          }    
          return a.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            prime Ankur Sharma
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes