本页内容

测试与调试

Qt 提供了多种功能,可帮助您开发高质量的代码。其中既有协助调试以追踪错误的功能,也有有助于防止错误出现的测试工具。

单元测试

Qt Test 支持创建单元测试,用于测试类、函数或整个库等接口。

  • Qt Test (也称为testlib)——一个用于 C++ 代码单元测试的框架
  • Qt Quick Test - 用于 QML 代码单元测试的框架

自动测试

Qt本身包含大量使用Qt Test 和Qt Quick Test 框架编写的单元测试(即autotests)。这些autotests位于各Qt模块源代码的tests/auto 目录中,可供学习参考。autotests是Qt开发过程中持续质量保证的重要组成部分。

使用Qt Creator

Qt Creator的完整调试工作流不仅支持对 C++ 和 QML 代码进行调试,还具备代码性能分析功能。

如需了解更多信息,请参阅Qt Creator 文档:

调试技巧

这些页面提供了针对各种情况的调试建议:

© 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.