summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qimagewriter.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@viroteck.net>2016-12-22 11:29:19 +0100
committerRobin Burchell <robin.burchell@viroteck.net>2016-12-22 11:51:19 +0000
commit04fbca3c91b58f1c3a212b234d238053d01f441a (patch)
tree5b63de70519cda6f69c22bba0f88dcd3241a3d58 /src/gui/image/qimagewriter.cpp
parent16829f0bae1a0ea24a31bc3101ad33ddf55aa261 (diff)
QImageWriter: Do not assume that QIODevice::open() will succeed
For instance, if we are passed a QFile to a path that does not exist, being told "No such file or directory" is significantly more useful than being told "Device not writable". Change-Id: I0cc72322f868f06ae2f77b3d0fac7e2094a1d2c7 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/image/qimagewriter.cpp')
-rw-r--r--src/gui/image/qimagewriter.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index fd2c51ebd8..ab15d8ee29 100644
--- a/src/gui/image/qimagewriter.cpp
+++ b/src/gui/image/qimagewriter.cpp
@@ -283,8 +283,13 @@ bool QImageWriterPrivate::canWriteHelper()
errorString = QImageWriter::tr("Device is not set");
return false;
}
- if (!device->isOpen())
- device->open(QIODevice::WriteOnly);
+ if (!device->isOpen()) {
+ if (!device->open(QIODevice::WriteOnly)) {
+ imageWriterError = QImageWriter::DeviceError;
+ errorString = QImageWriter::tr("Cannot open device for writing: %1").arg(device->errorString());
+ return false;
+ }
+ }
if (!device->isWritable()) {
imageWriterError = QImageWriter::DeviceError;
errorString = QImageWriter::tr("Device not writable");