The problem: When constructed with a filename or a QFile object, QImageWriter is able to determine the desired format from the filename. For safety, it should be easy to use QSaveFile in place of QFile, but this is not the case here: When constructed with a QSaveFile device, the format must be set explicitly.
By locality, the documentation gives the impression that the format is determined at construction time when given a filename. But at construction time, the filename is used only to construct a QFile object. If setting a QSaveFile device after QImageWriter construction, the ability to determine the format is lost.
The cause: The format is determined lazily in createWriteHandlerHelper() from the filename only if it the device can be cast to a QFile.
However, the filename() property comes from QFileDevice, the common base class of QFile and QSaveFile.
The proposal: Use QFileDevice, not QFile, to determine the format from the filename.