Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.15.2, 6.2.2
-
None
-
macOS Monterey
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