QImageWriter: Explain slightly strange looking logic in canWrite

Change-Id: Ic0fa4783351144ad8739669f1655b2fb0639a43d
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Robin Burchell 2016-12-22 11:31:12 +01:00
parent e1113cae98
commit 16829f0bae

View File

@ -705,6 +705,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;