使用 Cppcheck 检测 C++ 代码中的错误
启用 Cppcheck 实验插件,即可在 C++ 编辑器中查看 Cppcheck 工具生成的诊断信息。
Cppcheck 会在打开的文件上自动运行。要在当前活动项目中选择要检查的文件,请访问Analyze >Cppcheck 。
分析所选文件
- 转至Analyze >Cppcheck 。
- 在 uicontrol Binary 中,输入 Cppcheck 可执行文件的路径。
- 在Checks 中,选择要执行的检查。
注意: 默认情况下,Cppcheck 使用多个线程执行检查。选择Unused functions 可关闭默认行为。
- 在Custom arguments 中,输入运行 Cppcheck 的其他参数。这些参数可能会被自动生成的参数遮挡。为避免配置中可能出现的冲突,请选择Show raw output 并检查最终参数。
- 在Ignored file patterns 中,输入用于忽略匹配模式(通配符)的文件的过滤器。可以输入多个以逗号分隔的模式。尽管 Cppcheck 不会在匹配模式的文件上运行,但如果其他文件包含这些模式,它们可能会被隐式检查。
- 选择Inconclusive errors 还可标记可能的误报。
- 选择Check all define combinations 可检查所有定义组合。这会大大降低分析速度,但可能有助于发现更多问题。
- 选择Add include paths 可将当前项目的包含路径传递给 Cppcheck。这会减慢对大型项目的检查速度,但有助于 Cppcheck 发现丢失的包含。
- 选择Calculate additional arguments 以根据当前项目的设置(如使用的语言和标准版本)计算附加参数并将其传递给 Cppcheck。
- 选择要运行 Cppcheck 的文件。
- 选择Analyze 。
Qt Creator 在所选文件上运行 Cppcheck,并通过文本标记或注释显示结果。
要指定上述自动运行检查的设置,请访问首选项>Analyzer >Cppcheck 。
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.