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>
This commit is contained in:
parent
16829f0bae
commit
04fbca3c91
@ -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");
|
||||
|
Loading…
x
Reference in New Issue
Block a user