当前位置: 首页 > news >正文

Qt Creator使用Clang Format方法

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 -style=file 的意思,意味着 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系统:

http://www.lryc.cn/news/147464.html

相关文章:

  • 智慧矿山2.0:煤矿智能化综合管理AI大数据监管平台建设方案设计
  • Linux——(第一章)Linux的入门
  • 十六、策略模式
  • Python装饰器
  • 【Spring】使用自定义注解方式实现AOP鉴权
  • Go几种读取配置文件的方式
  • 每日一题(反转链表)
  • 某人事系统架构搭建设计记录
  • uniapp 实现切换tab锚点定位到指定位置
  • 华纳云:ssh登录22号端口拒绝连接Ubuntu?
  • python conda实践 sanic框架gitee webhook实践
  • LeetCode——无重复的最长子串(中等)
  • 【SQL】关系模型与查询和更新数据
  • 【Centos8_配置单节点伪分布式Spark环境】
  • 【软考】系统集成项目管理工程师(三)信息系统集成专业技术知识①【16分】
  • 揭秘特权账号潜在风险,你中招了吗?
  • 线性代数的学习和整理13: 定义域,值域,到达域 和单射,满射,双射,反函数,逆矩阵
  • 深入MaxCompute -第十一弹 -QUALIFY
  • Mysql定时备份事件
  • 探索ClickHouse——安装和测试
  • 常用的css样式
  • 小兔鲜儿 - 微信登录
  • C++ Primer阅读笔记--对象移动(右值引用、移动迭代器和引用限定符的使用)
  • 【办公类-16-01-02】2023年度上学期“机动班下午代班的排班表——跳过周三、节日和周末”(python 排班表系列)
  • ChatGPT HTML JS Echarts实现热力图展示
  • JavaScript七小知
  • Ubuntu【系统环境下】【编译安装OpenCV】【C++调用系统opencv库】
  • AR界安卓在中国,Rokid引爆空间计算狂潮
  • 在 React 中如何使用定时器
  • Unity记录4.6-存储-第四阶段总结