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

Please add a nicer way to return errors

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 5.14.0
    • Core: Other
    • None

    Description

      There are libraries like this, this or this, but I'd like to use something officially supported and endorsed by Qt. What it could look like:

      QExpected<QByteArray, QString> readFile(const QString &path)
      {
          QFile file(path);
          if (!file.open(QIODevice::ReadOnly)) {
              return qUnexpected(file.errorString());
          }
          auto result = file.readAll();    
          if (file.error() != QFileDevice::NoError) {        
              return qUnexpected(file.errorString());   
          }
          return result;
      }
      
      auto result = readFile(path);
      if (result) {
          qDebug() << result.value();
      } else {
          qDebug() << result.error();
      }
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            lamefun Banana Fool
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes