qtcreator 格式化代码
1. 关于 -> 插件 -> 选中Beautifier,重启qtcreator。2. 下载astyle 官网下载:https://sourceforge.net/projects/astylewindows 免安装,Linux需要自行编译。3. qtcreator 重启后,打开工具 -> Beautifier,勾选 Enable auto format on...
·
1. 关于 -> 插件 -> 选中Beautifier,重启qtcreator。
2. 下载astyle 官网下载: https://sourceforge.net/projects/astyle
windows 免安装,Linux需要自行编译。
3. qtcreator 重启后,打开工具 -> Beautifier,勾选 Enable auto format on file save.
4. 切换到Artistic Style,Artistic Style command,选择astyle 下载后存放的位置,我这里与qt安装目录放到了一起
5. 设置代码格式化规则
下面是我使用的代码格式话规则,方便各位复制粘贴,name随意起,我这里写的是 astyle
--style=bsd #大括号独占一行,上下对齐
--convert-tabs #将TAB符转化成空格,由转化参数指定,引号内的不转化
--indent=spaces=4 #缩进4个空格
--attach-closing-while #(while紧贴)
--indent-switches #缩进case标签
#--indent-namespaces #缩进命名空间块
--indent-continuation=4 #等号=或(结尾后续本语句符号插入空格,默认为1,可取1~4
--indent-preproc-block #缩进#开头的预处理语句
--indent-preproc-define #缩进以反斜杠结尾的多行预处理器定义
--indent-preproc-cond #预处理语句也缩进
--indent-col1-comments #注释也缩进
--pad-oper #操作符间插入空格
#--pad-comma #逗号间插入空格(--pad-oper中已有此效果)
#--pad-paren-in #括号里内插入空格
--unpad-paren #紧凑括号内外
#--delete-empty-lines #清除函数间的空行
--align-pointer=type #指针符号紧贴哪 type middle name
--align-reference=type #&符号紧贴哪 type middle name
#--break-elseifs #else if 之间换行
--add-braces #在'if', 'for', 'while'等句块中只有一行也加入大括号
--attach-return-type-decl #返回类型紧贴符号名
确定,保存。
注意: 只有在代码发生修改,然后保存代码时才会生效。原来已经写好的代码,没有做过修改保存,是不会生效的。
更多推荐
已为社区贡献1条内容
所有评论(0)