QImage: when saving fails, print the writer's error string

In debug builds, don't fail silently in QImage::save, but emit the error
string of the QImageWriter to the warning stream so that developers have
a chance to know what's going on.

Task-number: QTBUG-103257
Task-number: QTBUG-41043
Pick-to: 6.5
Change-Id: I29718b1445d0c99a3b35d57b58ec915a503cd5f0
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Volker Hilsheimer 2023-04-07 00:43:34 +02:00
parent 6f37399cd6
commit 3c83b3c010

View File

@ -3900,10 +3900,15 @@ bool QImage::save(QIODevice* device, const char* format, int quality) const
bool QImageData::doImageIO(const QImage *image, QImageWriter *writer, int quality) const
{
if (quality > 100 || quality < -1)
qWarning("QPixmap::save: Quality out of range [-1, 100]");
qWarning("QImage::save: Quality out of range [-1, 100]");
if (quality >= 0)
writer->setQuality(qMin(quality,100));
return writer->write(*image);
const bool result = writer->write(*image);
#ifdef QT_DEBUG
if (!result)
qWarning("QImage::save: failed to write image - %s", qPrintable(writer->errorString()));
#endif
return result;
}
/*****************************************************************************