Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.14.0
-
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(); }