Analyzing Code with Cppcheck

Cppcheck is a static analysis tool that detects errors in C++ code. Static analysis is performed on the source code without actually executing the application.

The experimental Cppcheck Diagnostics plugin integrates diagnostics that are generated by the Cppcheck tool into the C++ editor.

To enable running Cppcheck automatically on currently open files:

  1. Select Help > About Plugins > Code Analyzer > Cppcheck to enable the plugin.
  2. Restart Qt Creator to load the plugin.
  3. Select Tools > Options > Analyzer > Cppcheck to specify settings for running Cppcheck.

    "Cppcheck options"

  4. In the Binary field, enter the path to the Cppcheck executable file.
  5. In the Checks group, select the checks to perform on currently open files.

    Note: By default, Cppcheck uses multiple threads to perform checks. Selecting the Unused functions option disables the default behavior.

  6. In the Custom arguments field, enter additional arguments for running Cppcheck. The arguments might be shadowed by automatically generated ones. To avoid possible conflicts in configuration, select the Show raw output check box to see the final arguments.
  7. In the Ignored file patterns field, enter a filter for ignoring files that match the pattern (wildcard). You can enter multiple patterns separated by commas. Even though Cppcheck is not run on files that match the provided patterns, they might be implicitly checked if other files include them.
  8. Select the Inconclusive errors check box to also mark possible false positives.
  9. Select the Check all define combinations check box to check all define combinations. Enabling this option can significantly slow down analysis, but might help to find more issues.
  10. Select the Add include paths check box to pass the current project's include paths to Cppcheck. Enabling this option slows down checks on big projects, but can help Cppcheck to find missing includes.
  11. Select the Calculate additional arguments check box to calculate additional arguments based on current project's settings (such as the language used and standard version) and pass them to Cppcheck.

Qt Creator automatically runs Cppcheck on currently opened documents and displays results via text marks or annotations.

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