Obsolete Members for QTest

QTest 类的以下成员已被废弃。提供这些成员是为了确保旧源代码能够继续运行。我们强烈建议在新代码中不要使用它们。

函数

(deprecated in 6.4) bool compare_helper(bool success, const char *failureMsg, char *actualVal, char *expectedVal, const char *actual, const char *expected, const char *file, int line)
(deprecated in 6.3) void qWarn(const char *message, const char *file = nullptr, int line = 0)

宏

(deprecated in 6.3) QVERIFY_EXCEPTION_THROWN(expression, exceptiontype)
(deprecated) QWARN(message)

函数文档

[deprecated in 6.4] bool QTest::compare_helper(bool success, const char *failureMsg, char *actualVal, char *expectedVal, const char *actual, const char *expected, const char *file, int line)

自 6.4 版本起,此函数已被废弃。我们强烈建议不要在新代码中使用它。

该函数由 QTest::qCompare 的各种特化类调用,用于决定是否报告失败以及生成详细的测试输出。

failureMsg 参数可以为空,在这种情况下,如果比较失败,将输出默认消息。如果比较成功,则不会输出 failureMsg。

使用此函数并非最佳选择,因为它要求预先计算actualVal 和expectedVal 的字符串表示形式,尽管这些表示形式仅在比较失败时才会被使用。对于此类情况,请优先使用接受 qxp::function_ref() 作为参数的 compare_helper() 重载函数。

如果调用者创建了一个显示比较值的自定义失败消息,或者这些值无法转换为字符串,请使用不带actualVal 和expectedVal 参数的函数重载版本。

[deprecated in 6.3] void QTest::qWarn(const char *message, const char *file = nullptr, int line = 0)

自 6.3 版起,此函数已弃用。我们强烈建议不要在新代码中使用它。

请改用qWarning()。

宏文档

[deprecated in 6.3] QVERIFY_EXCEPTION_THROWN(expression, exceptiontype)

自 6.3 版本起,此宏已被废弃。我们强烈建议不要在新代码中使用它。

请改用QVERIFY_THROWS_EXCEPTION(exceptiontype, expression) 。

[deprecated] QWARN(message)

此宏已弃用。我们强烈建议不要在新代码中使用它。

请改用qWarning()。

将message 作为警告追加到测试日志中。此宏可在测试中的任意位置使用。

注意:此宏是线程安全的。

© 2026 The Qt Company Ltd. 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.