本页内容

Utils::Result Class

template <typename T = void> class Utils::Result

Result<T> 用于从函数中返回成功值或错误字符串。更多内容...

Header: #include <Result>

详细说明

Result 类型定义是 `expected<T, QString>` 的简写形式,在成功的情况下返回预期类型的值(T ),而在异常情况下则返回给用户的错误消息。

当没有具体的成功值可返回时,请使用 `Result<> ` 作为类型(请勿使用 `Result<bool>`)。在这种情况下,返回 `Utils::ResultOk ` 表示成功。您还可以使用便捷函数 `Utils::makeResult ` 来合并成功和错误情况。

作为错误情况的便捷类,返回一个Utils::ResultError 值。

另请参阅 Utils::ResultOk 、Utils::ResultError 和Utils::makeResult 。

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.