一 . 使用Clang Code模式來提醒語法和格式錯誤:html
1. 在插件中勾選 ClangCodeModle選項c++
2. 新建檢測配置, 進入 Tools→Options→C++, 在Code Model標籤頁,點擊Manage按照須要編輯app
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.htmlspa
https://www.oschina.net/news/98177/qt-creator-4-7-0-released.net
二) 代碼格式化工具prototype
QtCreator提供了一個Beautifier插件,用於加載外部工具(Artistic Style、ClangFormat、Uncrustify)對代碼進行格式化。插件
Beautifier會將源代碼解析爲結構模塊,如賦值語句、IF語句塊、循環體等等,並用Beautifier指定的選項對模塊進行格式化。
Beautifier可使用預約義和自定義風格對代碼進行格式化。c++11
1.首先確認插件是否安裝code
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