diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2021-07-13 17:14:11 +0200 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2021-07-14 11:02:25 +0000 |
commit | f0510d5bd2f1ed1dc76f6f89fb24566045d9ade7 (patch) | |
tree | c059ec66a438e2a7c1f6f7920f2f4a47856d15b2 /src/gui/image | |
parent | a7564e2657dcbd2f69c357d7c49c9326a23ee021 (diff) |
Improve support for saving QImage to QSaveFile
When saving to a QIODevice, QImage and QImageWriter will automatically
deduct the file format from the filename if it determines that the
device is a QFile. That did not work for a QSaveFile device. Fix by
using the common ancestor, QFileDevice, in the implementation.
Fixes: QTBUG-89022
Pick-to: 6.2
Change-Id: Ie01d80df4f29ca0d4ff30bf7e1b77605293c070e
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/image')
-rw-r--r-- | src/gui/image/qimagewriter.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp index 519a222db1..668d366208 100644 --- a/src/gui/image/qimagewriter.cpp +++ b/src/gui/image/qimagewriter.cpp @@ -153,7 +153,7 @@ static QImageIOHandler *createWriteHandlerHelper(QIODevice *device, // if there's no format, see if \a device is a file, and if so, find // the file suffix and find support for that format among our plugins. // this allows plugins to override our built-in handlers. - if (QFile *file = qobject_cast<QFile *>(device)) { + if (QFileDevice *file = qobject_cast<QFileDevice *>(device)) { if (!(suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1()).isEmpty()) { #ifndef QT_NO_IMAGEFORMATPLUGIN const int index = keyMap.key(QString::fromLatin1(suffix), -1); @@ -428,17 +428,17 @@ void QImageWriter::setFileName(const QString &fileName) } /*! - If the currently assigned device is a QFile, or if setFileName() + If the currently assigned device is a file, or if setFileName() has been called, this function returns the name of the file QImageWriter writes to. Otherwise (i.e., if no device has been - assigned or the device is not a QFile), an empty QString is + assigned or the device is not a file), an empty QString is returned. \sa setFileName(), setDevice() */ QString QImageWriter::fileName() const { - QFile *file = qobject_cast<QFile *>(d->device); + QFileDevice *file = qobject_cast<QFileDevice *>(d->device); return file ? file->fileName() : QString(); } @@ -719,7 +719,7 @@ bool QImageWriter::write(const QImage &image) if (!d->handler->write(img)) return false; - if (QFile *file = qobject_cast<QFile *>(d->device)) + if (QFileDevice *file = qobject_cast<QFileDevice *>(d->device)) file->flush(); return true; } |