Analyze code with Clang-Tidy and Clazy
Qt Creator comes with the following Clang tools for finding problems in C, C++, and Objective-C source code by using static analysis:
- Clang-Tidy, which has diagnostics and fixes for typical programming errors, such as style violations or interface misuse.
- Clazy, which helps Clang understand Qt semantics. It displays Qt related compiler warnings, ranging from unnecessary memory allocation to misuse of API and has refactoring actions for fixing some of the issues.
Note: The Clang static analyzer checks are a part of Clang-Tidy. To use the checks, you must create a custom configuration for the Clang tools and enable them for Clang-Tidy.
To run Clang-Tidy or Clazy to analyze the currently open file:
- Select the (Analyze File) button on the editor toolbar, and then select the tool: Clang-Tidy or Clazy.
- Select Tools > C++ > Analyze Current File with Clang-Tidy or Analyze Current File with Clazy.
To run Clang-Tidy or Clazy to analyze an open project:
- Select Analyze > Clang-Tidy or Clazy.
- Select the files to apply the checks to.
- Select Analyze to start the checks.
The Clang-Tidy or Clazy view shows the issues:
Diagnostics in the Clang-Tidy view.
Note: If you select Debug in the mode selector to open the Debug mode and then select Clang-Tidy or Clazy, you must select the (Start) button to open the Files to Analyze dialog.
Double-click an issue to move to the location where the issue appears in the code editor.
If a fixit exists for an issue, you can select the check box next to the issue to schedule it for fixing. Select the Select Fixits check box to select all fixits. To see the status of an issue, hover the mouse pointer over the icon next to the check box.
To see more information about an issue that is marked with the icon, hover the mouse pointer over the line.
Select the button to customize diagnostics for the current project.
To disable checks of a particular type either globally or for a particular project, select Disable This Check or Disable These Checks in the context menu.
In addition to running the tools to collect diagnostics, you can select to load diagnostics from YAML files that you exported using the
-export fixes option.
© 2024 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.