diff options
author | Robin Burchell <robin.burchell@crimson.no> | 2017-03-15 17:49:20 +0100 |
---|---|---|
committer | Robin Burchell <robin.burchell@crimson.no> | 2017-03-22 15:40:55 +0000 |
commit | 66e162e8f19f8a1f9b4f96008f2853be7fc1822e (patch) | |
tree | de502e972be3246b3658a96ef096d638d33b0bf5 | |
parent | 108956b53ee9093f0fca3410866ec1f2317b42a2 (diff) |
QImageReader: Pass up information about resource errors on open
If a system runs out of FDs, there is no sense in trying to autodetect
the format - as the real problem is the lack of FDs, not the
non-existent file.
Change-Id: I3302340859c3cc62995ac1b7b3c7b6e6326cb43e
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r-- | src/gui/image/qimagereader.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp index 2f25f4dcbc..55c3a4704a 100644 --- a/src/gui/image/qimagereader.cpp +++ b/src/gui/image/qimagereader.cpp @@ -564,6 +564,16 @@ bool QImageReaderPrivate::initHandler() // probe the file extension if (deleteDevice && !device->isOpen() && !device->open(QIODevice::ReadOnly) && autoDetectImageFormat) { + Q_ASSERT(qobject_cast<QFile*>(device) != 0); // future-proofing; for now this should always be the case, so... + QFile *file = static_cast<QFile *>(device); + + if (file->error() == QFileDevice::ResourceError) { + // this is bad. we should abort the open attempt and note the failure. + imageReaderError = QImageReader::DeviceError; + errorString = file->errorString(); + return false; + } + QList<QByteArray> extensions = QImageReader::supportedImageFormats(); if (!format.isEmpty()) { // Try the most probable extension first @@ -574,7 +584,6 @@ bool QImageReaderPrivate::initHandler() int currentExtension = 0; - QFile *file = static_cast<QFile *>(device); QString fileName = file->fileName(); do { |