The cause is the habitual want to format code, found QT creater default incredibly is no code format, only one indentation, make wool Ah!!!
Search the next, it is easy to search, Qt creater has a plugin:beautifier, in the help-about the plug -in can be opened (need to restart).
Unfortunately, this is just an interface, and its role is to call the Format tool for formatting. -it took two hours to realize! The painful lesson tells us, must look the official document , does not want to take the shortcut!
Officially, it supports three external tools:artistic Style, Clangformat, Uncrustify . And it's all provided.
This is illustrated only by Clangformat .
Clangformat is a sub-function of LLVM, LLVM is something like GCC.
So, want to use Clangformat , you need to download LLVM, according to the above address, search for their own version can be. I'm a win64 here.
The path option does not matter when installing, because Qt Creater's beautifier Clang Format option allows you to either search by path or specify the path yourself.
Once the LLVM is installed, you can set the Clang Format option.
Configure the path first (for example:C:\Program files\llvm\bin\clang-format.exe );
Then choose the code style, default is LLVM, Google, Chromium, Mozilla, WebKit, File, also can be customized.
The default style, you need to focus on File -because the other styles are the given style, and file is not.
file is clang-format.exe-style=file meaning that clang-format.exe will search for the style file ( *. Clang-format file).
Note that its search path is the folder in which the current file is located or the current item (it is not known whether it will continue to search the upper level-at least, the workspace has not been validated successfully).
In this case, it requires that the . Clang-format file be placed in the project folder, which is inconsistent with my habits.
Custom styles
Fortunately, there is one more option: Usecustomized Style-add .
As follows
The Value section reads as follows
accessmodifieroffset:0Alignescapednewlinesleft:falsealigntrailingcomments:trueAllowallparametersofdeclarationonnextline:falseAllowshortfunctionsonasingleline:falseAllowshortifstatementsonasingleline:falseAllowshortloopsonasingleline:falsealwaysbreakbeforemultilinestrings:falsealwaysbreaktemplatedeclarations:falsebinpackparameters:falsebreakbeforebinaryoperators:falsebreakbeforeternaryoperators:falseBreakconstructorinitializersbeforecomma:falseColumnlimit:128Breakbeforebraces:attachcommentpragmas:‘‘Constructorinitializerallononelineoroneperline:falseConstructorinitializerindentwidth:0Continuationindentwidth:0Cpp11bracedliststyle:falsederivepointerbinding:falseIndentcaselabels:trueIndentfunctiondeclarationaftertype:falseIndentwidth:4Language:cppmaxemptylinestokeep:1Namespaceindentation:noneobjcspaceafterproperty:trueobjcspacebeforeprotocollist:trueObjcblockindentwidth:4Penaltybreakbeforefirstcallparameter:100penaltybreakcomment:100penaltybreakfirstlessless:0penaltybreakstring:100Penaltyexcesscharacter:1Penaltyreturntypeonitsownline:20spacebeforeassignmentoperators:truespacebeforeparens:controlstatementsspaceinemptyparentheses:falsespacesbeforetrailingcomments:1Spacesinangles:falsespacesincstylecastparentheses:falsespacesincontainerliterals:falsespacesinparentheses:falseTabwidth:4Usetab:never
PS: The above configuration is search, forget the source of ~
Use
tool-beautifier-clangformat There are two options in the format of the current file , formatting the selection .
However, this is cumbersome and difficult to use. So it is best to set a shortcut key for it, my is alt+ctrl+l (IntelliJ shortcut key).
Note thatClangformat has a special option Format entire file if no text was selected , it is recommended that this option be selected so that only a C11>format Selected Text shortcut key.
Reference:
beautifying Source Code
Clang-format Style Options
The use of Clang-format in Qt creater