从 ​​http://cppcheck.sourceforge.net/​​   下载最新的cppcheck。

代码检查工具 cppcheck 的使用_html

根据自己环境下载相应的版本:

下载后,安装即可:

安装后,

代码检查工具 cppcheck 的使用_qt_02

其中cppcheckgui.exe是可视化程序,用于检测代码。还有一种就是命令方式,和集成到qt中使用

命令方式:

代码检查工具 cppcheck 的使用_visual-studio_03

1、VS

参考这里(​​http://avitebskiy.blogspot.tw/2012/10/poor-mans-visual-studio-cppcheck.html​​),可以方便的把cppcheck嵌入到vs,然后可以方便的对一个文件进行检查,而且支持错误跳转。


  • click theAddbutton
  • set theTitle, for exampleCppcheck
  • setCommandtoC:\Program Files (x86)\Cppcheck\cppcheck.exe
  • setArgumentsto --quiet --verbose --template=vs $(ItemPath)
  • setInitial Directoryto$(ItemDir)
  • make sure Use Output windowcheckbox is enabled
  • click on theMove Upbutton repeatedly until your entry is at the top of the list, this will make it easier to identify you new command as you can count on it being calledTools.ExternalCommand1
  • clickOK.


qt方式:参数中:--enable=all %{CurrentProject:Path},工作目录:%{CurrentProject:Path}

代码检查工具 cppcheck 的使用_html_04

使用方法:

代码检查工具 cppcheck 的使用_ide_05

检测结果:

代码检查工具 cppcheck 的使用_ide_06