Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70033

QIODevice::close() should return a boolean (e.g. to handle disk-full situations)

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P3: Somewhat important
    • Resolution: Unresolved
    • Affects Version/s: 5.11.1
    • Fix Version/s: None
    • Component/s: Core: I/O
    • Labels:
      None
    • Platform/s:
      All

      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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              • Assignee:
                thiago Thiago Macieira
                Reporter:
                dfaure_kdab David Faure
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes