Qt Creator使用clang-format实现源代码格式化排版(Windows/macOS1)

简介: Qt Creator使用clang-format实现源代码格式化排版(Windows/macOS)

本篇先针对Windows系统来描述,末尾再补充macOS


1、clang官网下载clang-format.exe


https://releases.llvm.org/download.html  下载最新版本


https://github.com/llvm/llvm-project/releases


方法1:完整版

我们需要从官网下载完整的LLVM编译器,Pre-Built Binaries,Windows (64-bit),LLVM-9.0.0-win64.exe。安装时,请勾选添加环境变量,Add  LLVM to the system PATH for all users。


安装完毕之后,把C:\Program Files\LLVM\bin目录下的clang-format文件和clang-tidy复制到某个文件夹里,比如


F:\Qt\Qt5.12.7\Tools\QtCreator\bin\clang\bin9\  这里的bin9是新建的文件夹,区别于原来的bin


方法2:单独版

单独版就不需要从官网下载完整的LLVM编译器,因为完整版太大了,包含很多其他工具,没必要。


我们仅仅从https://llvm.org/builds/,下载clang-format-2663a25f.exe即可,网页截图如下:



image.png



下载后把clang-format-2663a25f.exe拷贝到路径F:\Qt\Qt5.12.7\Tools\QtCreator\bin\clang\bin\


clang-format官方文档说明

http://clang.llvm.org/docs/ClangFormatStyleOptions.html


https://clang.llvm.org/docs/ClangFormat.html


如果你的电脑安装了VS2017以上版本,那么该版本自带了clang-format.exe,路径是C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\vcpackages


但是VS2017自带的clang-format的LLVM版本是v6.0,比较旧,不建议使用了。


2、Qt Creator Clang-Tidy设置


在Qt Creator里,点击Tools(工具)->Options(选项)->Analyzer(分析器),


在Clang-Tidy填写F:\Qt\Qt5.12.7\Tools\QtCreator\bin\clang\bin\clang-tidy.exe


在Diagnostic configuration里选择Clang-Tidy and Clazy preselected checks [built-in]。


image.png


3、Qt Creator Clang-format插件


Qt Creator,在Help栏里,选择About Plugins,勾上Beautifier,重启qtcreator;


image.png


选择Tools->Options,点击左栏的Beautifier,选择Clang Format;


Clang format的路径填写:F:\Qt\Qt5.12.7\Tools\QtCreator\bin\clang\bin\clang-format-2663a25f.exe


在Options里选择use customized style,Add新建一个配置,名称随意取,例如myclangconfig;


image.png



相关文章
|
监控 编译器 Windows
Qt5实现Windows平台串口通信
Qt5实现Windows平台串口通信
|
Windows
Windows下对于Qt中带 / 的路径的处理
Windows下对于Qt中带 / 的路径的处理
347 9
|
存储 算法 C++
【Qt应用开发】复刻经典:基于Qt实现Windows风格计算器(加减乘除、删除、归零功能全解析)
在Qt中,"栈"的概念主要体现在两个层面:一是程序设计中的数据结构——栈(Stack),二是用户界面管理中的QStackedWidget控件。下面我将分别简要介绍这两个方面:
804 4
|
数据管理 Linux iOS开发
Splunk Enterprise 9.4.5 (macOS, Linux, Windows) - 机器数据管理和分析
Splunk Enterprise 9.4.5 (macOS, Linux, Windows) - 机器数据管理和分析
531 0
|
Linux 虚拟化 iOS开发
VMware Workstation 17.6.4 Pro macOS Unlocker & OEM BIOS 2.7 for Windows
VMware Workstation 17.6.4 Pro macOS Unlocker & OEM BIOS 2.7 for Windows
2610 1
|
Dart Linux iOS开发
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
1565 0
JEB Pro v5.30 (macOS, Linux, Windows) - 逆向工程平台
|
Unix Linux iOS开发
Splunk Enterprise 10.0.0 (macOS, Linux, Windows) - 搜索、分析和可视化,数据全面洞察平台
Splunk Enterprise 10.0.0 (macOS, Linux, Windows) - 搜索、分析和可视化,数据全面洞察平台
432 0
|
Linux iOS开发 MacOS
Gitea Enterprise 23.4.0 (Linux, macOS, Windows) - 本地部署的企业级 Git 服务
Gitea Enterprise 23.4.0 (Linux, macOS, Windows) - 本地部署的企业级 Git 服务
619 0
Gitea Enterprise 23.4.0 (Linux, macOS, Windows) - 本地部署的企业级 Git 服务
|
数据管理 Linux iOS开发
Splunk Enterprise 9.4.1 (macOS, Linux, Windows) 发布 - 机器数据管理和分析
Splunk Enterprise 9.4.1 (macOS, Linux, Windows) 发布 - 机器数据管理和分析
503 0
Splunk Enterprise 9.4.1 (macOS, Linux, Windows) 发布 - 机器数据管理和分析
|
编译器 Windows
plugin cannot be loaded for module “QtQuick“ && Could not load the Qt platform plugin “windows“
本文讨论了在Qt应用程序中遇到的平台插件加载问题,包括具体的错误信息、解决方案和参考链接。问题表现为无法加载“QtQuick”模块的插件,并且无法找到“windows”平台插件。解决方案是修改环境变量`Qt5_DIR`以使用正确的Qt版本和编译器环境。
1578 2

热门文章

最新文章

推荐镜像

更多
  • qt