宠物美容网站建设合同书,百度网站管理员工具,网站内容模板,有flash的网站Qt Creator使用Clang Format
习惯性的想格式化代码#xff0c;发现Qt Creator默认居然是没有代码格式化的#xff0c;只有一个缩进。 Qt Creater中有个插件#xff1a;beautifier#xff0c;在帮助-关于插件中#xff0c;开启“Beautifier”即可#xf…Qt Creator使用Clang Format
习惯性的想格式化代码发现Qt Creator默认居然是没有代码格式化的只有一个缩进。 Qt Creater中有个插件beautifier在帮助-关于插件中开启“Beautifier”即可会提醒需要重启Qt creator。 注Qt Creator安装包中不包含这个格式化工具它的作用是调用格式化工具进行格式化。
windows系统
安装
官方的说支持三种外部格式化工具Artistic Style、ClangFormat、Uncrustify 。 这里仅以 ClangFormat 来说明 ClangFormat 是LLVM的一个子功能LLVM是类似GCC的东西。 https://github.com/llvm/llvm-project/releases/
所以想用 ClangFormat 就需要下载LLVM根据上面的地址搜索适合自己的版本即可。 安装LLVM的时候PATH选项无所谓因为Qt Creater的beautifier的Clang Format选项中既可以根据PATH搜索也可以自行指定路径。
配置
安装好LLVM之后就可以设置 Clang Format 选项。 “编辑-preferences”; “Beautifier-Clang Format”: Configure: Clang Format command: 先配置路径如C:\Program Files\LLVM\bin\clang-format.exe
选择代码样式
默认样式和自定义样式。
默认样式LLVM、Google、Chromium、Mozilla、WebKit、File
需要重点说一下File样式 因为其他的样式都是给定的样式而 File 则不是。 File 是 clang-format.exe -stylefile 的意思意味着 clang-format.exe 会去搜索样式文件 *.clang-format 文件。 需要注意的是它的搜索路径是当前文件所在的文件夹或者当前项目。
自定义样式Options - Use customized style - Add
AccessModifierOffset: 0
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 128
BreakBeforeBraces: Attach
CommentPragmas:
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 0
Cpp11BracedListStyle: false
DerivePointerBinding: false
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ObjCBlockIndentWidth: 4
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 100
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 20
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
TabWidth: 4
UseTab: Never使用
工具-Beautifier-ClangFormat 里面有两个选项分别是格式化当前文件、格式化选定内容。
注也可使用快捷方式进行操作“编辑-preferences-环境-键盘-ClangFormat: ***
linux系统
macOS系统