Important: Please read the Qt Code of Conduct -

QImageWriter::supportedMimeTypes() jpeg

  • Hi,
    In screenShot example,

    void Screenshot::saveScreenshot()
        const QString format = "png";
        QString initialPath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
        if (initialPath.isEmpty())
            initialPath = QDir::currentPath();
        initialPath += tr("/untitled.") + format;
        QFileDialog fileDialog(this, tr("Save As"), initialPath);
        QStringList mimeTypes;
        foreach (const QByteArray &bf, QImageWriter::supportedMimeTypes())
        fileDialog.selectMimeTypeFilter("image/" + format);
        if (fileDialog.exec() != QDialog::Accepted)
        const QString fileName = fileDialog.selectedFiles().first();
        if (! {
            QMessageBox::warning(this, tr("Save Error"), tr("The image could not be saved to \"%1\".")

    After clicking "Save Screenshot" pushbutton, "Save As"
    dialog pops up. In "Files of type" combobox, I see several supported file
    formats such as .bmp, .jpeg, .jpg, .png, ...
    When I select "PNG image(.png)" comboBox, the "File name" lineEdit shows the file name with the extension changed automatically to myfile.png. but when I select "JPEG image(.jpeg *.jpg *.jpe)", the "File name:" LineEdit shows with the extension changed to myfile.jpeg. I want it to change its extension automatically to myfile.jpg instead of myfile.jpeg.
    How can I do this?

  • Lifetime Qt Champion


    Shot in the dark: remove all other extensions from the jpeg entry.

    Hope it helps

  • @SGaist
    How could I remove them? Do I have to modify the source code of Qt?

  • Lifetime Qt Champion

    No, when you populate mimeTypes, check if jpeg appears in the entry and modify it before adding it to mimeTypes.

  • @SGaist
    I tried it. But it did not work. Instead of supportedMimeTypes(), I decided to use supportedImageFormats() though it demands some extra work. Thanks anyway.

  • Lifetime Qt Champion

    You're welcome !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

Log in to reply