Qt Creator- Beautifier插件代碼格式化,使用 Clang Code Model


一 . 使用Clang Code模式來提醒語法和格式錯誤:

1. 在插件中勾選 ClangCodeModle選項

2. 新建檢測配置, 進入 Tools→Options→C++, 在Code Model標簽頁,點擊Manage按照需要編輯

 

 

ClangCodeModle配置(供參考):

-Weverything -Wno-unused-macros -Wno-newline-eof -Wno-exit-time-destructors -Wno-global-constructors -Wno-gnu-zero-variadic-macro-arguments 
-Wno-documentation -Wno-shadow -Wno-missing-prototypes -Wno-old-style-cast -Wno-deprecated -Wno-c++11-long-long -Wno-c++98-compat-pedantic
-Wno-writable-strings -Wno-covered-switch-default -Wno-variadic-macros -Wsuggest-attribute=pure -Wno-c++11-extensions -Wno-expansion-to-defined
-Wno-missing-field-initializers -Wno-zero-as-null-pointer-constant -Wno-disabled-macro-expansionue 

官方教程: https://doc.qt.io/qtcreator/creator-clang-codemodel.html

https://www.oschina.net/news/98177/qt-creator-4-7-0-released

二) 代碼格式化工具

QtCreator提供了一個Beautifier插件,用於加載外部工具(Artistic Style、ClangFormat、Uncrustify)對代碼進行格式化。

Beautifier會將源代碼解析為結構模塊,如賦值語句、IF語句塊、循環體等等,並用Beautifier指定的選項對模塊進行格式化。
Beautifier可以使用預定義和自定義風格對代碼進行格式化。

1.首先確認插件是否安裝

 

 2.配置

 

 

 

  

  

BasedOnStyle: LLVM
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: false
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: true
IndentBraces: false
BinPackParameters: false
BinPackArguments: false
Cpp11BracedListStyle: false
IndentWidth: 2
Standard: Cpp03
ColumnLimit: 80

3 設置快捷鍵 Ctrl+ALt+I ,然后可以選中要格式化的代碼使用 Ctrl+ALt+I 

  

其他格式可參考:https://blog.51cto.com/9291927/2112402

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM