Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12
-
None
-
f0510d5bd2f1ed1dc76f6f89fb24566045d9ade7 (qt/qtbase/dev) eafd0106178fe0129f6260007dad6e521f30681d (qt/qtbase/6.2)
Description
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.