[QT] In order to unify the code style in the company, how to set it in Qt Creator

1. Why do you need to manage code style?

Try to think about it, a programmer writes a program and commits it to the team's program management library. If other developers in the team need this function, then he will read the source code. As the saying goes, one thousand readers, one thousand Hamlet. Even if it is a language that is very strict for computers like code, it is absolutely impossible for us humans to abandon our inherent logical thinking, think like a computer, and understand this program like a program compiler. We can do What I got here is to read the source code, sort out my own set of logic, and then understand what this program does.
In short, the code style is a standard that must be unified in a team. If it is not unified, the interface calls between different programs will be messy, and the team members will not have a clearer understanding of the framework of the entire program.

After setting a unified code style, no matter what your habit of writing code is, after you save it, the format of the code will be unified, which is very convenient.

2. Configure Beautifier: Help → About Plugins, check Beautifier, and restart Qt

insert image description here
insert image description here

3. Set format

3.1 Get clang-format.exe

How to obtain clang-format.exe and clang-format_2.txt:

Link: https://pan.baidu.com/s/1HAW_Lac89NTaz9A64A7GNw
Extraction code: 1024

Save clang-format.exe to your qt installation directory, To facilitate the selection of the following operations

3.2 Tools → Options

insert image description here

3.3 Beautifier → General → Check Enable auto format on file save → Select ClangFormat

insert image description here

2.3 Beautifier → Clang Format → Browse → select clang-format.exe → Add → copy the contents of clang-format_2.txt into it

insert image description here
Click Browse to select the file, select the previously extracted clang-format.exe
insert image description here
and copy the contents of clang-format_2.txt to Value

Guess you like

Origin blog.csdn.net/WL0616/article/details/129958827