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

Wrong mapping between QFileDialog's filters and QImageWriter mime types

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.2.2
    • None
    • macOS Monterey
    • macOS

    Description

      Trying to execute the Screenshot Example I have incurred in what I believe is a bug.
      Mapping the QImageWriter supported mime types to the QFileDialog's mime type filters results in a wrong filename+extension when selecting a filter.

      Minimal Code to reproduce the issue:

      #include <QApplication>
      
      #include <QFileDialog>
      #include <QImageWriter>
      #include <QMessageBox>
      #include <QStandardPaths>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          const QString format = "png";
          QString initialPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
          if (initialPath.isEmpty())
              initialPath = QDir::currentPath();
          initialPath += QObject::tr("/untitled.") + format;
      
          QFileDialog fileDialog(nullptr, QObject::tr("Save As"), initialPath);
          fileDialog.setAcceptMode(QFileDialog::AcceptSave);
          fileDialog.setFileMode(QFileDialog::AnyFile);
          fileDialog.setDirectory(initialPath);
          QStringList mimeTypes;
          const QList<QByteArray> baMimeTypes = QImageWriter::supportedMimeTypes();
          for (const QByteArray &bf : baMimeTypes)
              mimeTypes.append(QLatin1String(bf));
          fileDialog.setMimeTypeFilters(mimeTypes);
          fileDialog.selectMimeTypeFilter("image/" + format);
          fileDialog.setDefaultSuffix(format);
          if (fileDialog.exec() != QDialog::Accepted)
              return EXIT_SUCCESS;
          const QString fileName = fileDialog.selectedFiles().first();
          return a.exec();
      }
      

      Attachment dialog0.png
      Expected: filename untitled.png and filter png
      Actual: the QFileDialog has selected filter tiff and shows filename untitled.png

      Attachment dialog1.png
      Expected: filename untitled.bmp and filter selected bmp
      Actual: the QFileDialog has selected filter bmp and shows filename untitled.bmp

      Attachment dialog2.png
      Expected: filename untitled.heic and filter selected heif
      Actual : the QFileDialog has selected filter heif and shows filename untitled.heic

      Attachment dialog3.png
      Expected: filename untitled.jpg and filter selected jpeg
      Actual: the QFileDialog has selected filter jpeg and shows filename untitled.jp2

      Attachment dialog4.png
      Expected: filename untitled.icns and filter selected icns
      Actual: the QFileDialog has selected filter icns and shows filename untitled.webp

      Attachments

        1. dialog4.png
          dialog4.png
          65 kB
        2. dialog3.png
          dialog3.png
          68 kB
        3. dialog2.png
          dialog2.png
          64 kB
        4. dialog1.png
          dialog1.png
          66 kB
        5. dialog0-1.png
          dialog0-1.png
          63 kB
        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
            andrea.marangoni Andrea Marangoni
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes