Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.11.1
-
None
Description
When making a custom QIODevice on top of a QFile (like KArchive's KCompressionDevice), the actual writing to disk happens in QFile::close(). But the only way to know if that worked, is to call QFileDevice::error(), which is inconvenient in generic code that works with a QIODevice pointer. Downcasting to QFileDevice is necessary to check for errors.
Similarly, the custom QIODevice on top of that has no way to report those errors to its own users, because the QIODevice API only has errorString(), which must be called only when an error happened.
In both cases, given that close() returns void, we have no way to know that an error happened.
I think close() should return a boolean, because generally speaking, it doesn't just close, it flushes first, and that can fail, for any QIODevice.
If there's agreement I can look into writing the patch in gerrit, with #if QT_VERSION checks.
Downstream discussion and real-world code at https://phabricator.kde.org/D14890
Attachments
Issue Links
- relates to
-
QTBUG-70484 QIODevice read, readLine, readAll could report errors through optional bool* or lambda
- Open
-
QTBUG-99674 QFile::write() does not report errors
- Closed