diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-19 11:46:42 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2024-02-20 17:34:02 +0100 |
commit | 35def0334130b40410fc9bb3f805837e57ee59ed (patch) | |
tree | a75060ca98715b6ee777c43cf22f0f53dc6d0f49 /examples | |
parent | 229832178517c54e7b719207ec1d377d7180049d (diff) |
Use std::optional instead of bool to indicate success of de/encoding
QOpcUaGenericStructHandler is a new class in Qt 6.7, and has two
functions that return values but might fail. The modern C++ way of
doing this is to return a std::optional, rather than return a bool with
the value returned through an out-parameter (or a default-
constructed value with a boolean out-parameter to indicate success).
Found during API review.
Pick-to: 6.7
Change-Id: Ib2ba6098f53eccab73beace6844028d0b674ca65
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/opcua/opcuaviewer/treeitem.cpp | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/examples/opcua/opcuaviewer/treeitem.cpp b/examples/opcua/opcuaviewer/treeitem.cpp index c8ced61..1cbbc02 100644 --- a/examples/opcua/opcuaviewer/treeitem.cpp +++ b/examples/opcua/opcuaviewer/treeitem.cpp @@ -343,10 +343,9 @@ QString TreeItem::variantToString(const QVariant &value, const QString &typeNode if (mModel->genericStructHandler() && mModel->genericStructHandler()->dataTypeKindForTypeId(mModel->genericStructHandler()->typeIdForBinaryEncodingId(obj.encodingTypeId())) == QOpcUaGenericStructHandler::DataTypeKind::Struct) { - bool decodeSuccess = false; - const auto decodedValue = mModel->genericStructHandler()->decode(obj, decodeSuccess); - if (decodeSuccess) - return decodedValue.toString(); + const auto decodedValue = mModel->genericStructHandler()->decode(obj); + if (decodedValue) + return decodedValue->toString(); } return u"[TypeId: \"%1\", Encoding: %2, Body: 0x%3]"_s.arg(obj.encodingTypeId(), |