summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qimagewriter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/image/qimagewriter.cpp')
-rw-r--r--src/gui/image/qimagewriter.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index f3af2738af..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");
@@ -705,6 +710,11 @@ bool QImageWriter::canWrite() const
if (QFile *file = qobject_cast<QFile *>(d->device)) {
const bool remove = !file->isOpen() && !file->exists();
const bool result = d->canWriteHelper();
+
+ // This looks strange (why remove if it doesn't exist?) but the issue
+ // here is that canWriteHelper will create the file in the process of
+ // checking if the write can succeed. If it subsequently fails, we
+ // should remove that empty file.
if (!result && remove)
file->remove();
return result;