Skip to content

Commit a025d67

Browse files
committed
build: 更新Qt版本至6.11.1并完善工程配置规范
1. 更新VSCode、CI、打包脚本中的Qt 6.10.2路径为6.11.1 2. 新增项目代码规范文档:Qt6、C++20、CMake、QML、内存安全、错误处理等 3. 重构编译配置:替换旧的弃用定义宏,新增统一编译器警告设置 4. 优化路径引用和代码格式,修复部分clang-tidy检查规则 5. 调整qmake和cmake的输出目录、平台库配置逻辑
1 parent 47534b0 commit a025d67

22 files changed

Lines changed: 205 additions & 98 deletions

.clang-format

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,39 @@ AlignAfterOpenBracket: Align
55
AlignConsecutiveAssignments: false
66
AlignConsecutiveDeclarations: false
77
AlignEscapedNewlines: DontAlign
8-
AlignOperands: true
9-
AlignTrailingComments: true
8+
AlignOperands: Align
9+
AlignTrailingComments:
10+
Kind: Always
11+
OverEmptyLines: 1
1012
AllowAllParametersOfDeclarationOnNextLine: true
11-
AllowShortBlocksOnASingleLine: true
13+
AllowShortBlocksOnASingleLine: Always
1214
AllowShortCaseLabelsOnASingleLine: true
15+
AllowShortEnumsOnASingleLine: true
1316
AllowShortFunctionsOnASingleLine: Inline
14-
AllowShortIfStatementsOnASingleLine: false
15-
AlwaysBreakAfterDefinitionReturnType: None
16-
AlwaysBreakAfterReturnType: None
17+
AllowShortIfStatementsOnASingleLine: Never
18+
AllowShortLoopsOnASingleLine: false
1719
AlwaysBreakBeforeMultilineStrings: false
1820
AlwaysBreakTemplateDeclarations: Yes
1921
BinPackArguments: false
2022
BinPackParameters: false
2123
BraceWrapping:
2224
AfterClass: true
23-
AfterControlStatement: false
25+
AfterControlStatement: Never
2426
AfterEnum: false
2527
AfterFunction: true
2628
AfterNamespace: false
27-
AfterObjCDeclaration: false
2829
AfterStruct: true
2930
AfterUnion: false
3031
AfterExternBlock: false
3132
BeforeCatch: false
3233
BeforeElse: false
34+
BeforeLambdaBody: false
35+
BeforeWhile: false
3336
IndentBraces: false
3437
SplitEmptyFunction: false
3538
SplitEmptyRecord: false
3639
SplitEmptyNamespace: false
37-
BreakAfterJavaFieldAnnotations: false
40+
BreakAfterReturnType: None
3841
BreakBeforeBinaryOperators: All
3942
BreakBeforeBraces: Custom
4043
BreakBeforeTernaryOperators: true
@@ -44,13 +47,13 @@ BreakStringLiterals: true
4447
ColumnLimit: 100
4548
CommentPragmas: '^ IWYU pragma:'
4649
CompactNamespaces: false
47-
ConstructorInitializerAllOnOneLineOrOnePerLine: false
4850
ConstructorInitializerIndentWidth: 4
4951
ContinuationIndentWidth: 4
5052
Cpp11BracedListStyle: true
5153
DerivePointerAlignment: false
5254
DisableFormat: false
53-
ExperimentalAutoDetectBinPacking: false
55+
EmptyLineAfterAccessModifier: Never
56+
EmptyLineBeforeAccessModifier: LogicalBlock
5457
FixNamespaceComments: true
5558
ForEachMacros:
5659
- forever
@@ -67,30 +70,19 @@ IndentCaseLabels: false
6770
IndentPPDirectives: None
6871
IndentWidth: 4
6972
IndentWrappedFunctionNames: false
70-
JavaScriptQuotes: Leave
71-
JavaScriptWrapImports: true
73+
InsertNewlineAtEOF: true
7274
KeepEmptyLinesAtTheStartOfBlocks: false
7375
Language: Cpp
74-
MacroBlockBegin: ''
75-
MacroBlockEnd: ''
7676
MaxEmptyLinesToKeep: 1
7777
NamespaceIndentation: None
78-
ObjCBinPackProtocolList: Auto
79-
ObjCBlockIndentWidth: 4
80-
ObjCSpaceAfterProperty: false
81-
ObjCSpaceBeforeProtocolList: true
82-
PenaltyBreakAssignment: 150
83-
PenaltyBreakBeforeFirstCallParameter: 300
84-
PenaltyBreakComment: 500
85-
PenaltyBreakFirstLessLess: 400
86-
PenaltyBreakString: 600
87-
PenaltyBreakTemplateDeclaration: 10
88-
PenaltyExcessCharacter: 50
89-
PenaltyReturnTypeOnItsOwnLine: 300
78+
PackConstructorInitializers: NextLine
9079
PointerAlignment: Right
80+
QualifierAlignment: Left
81+
ReferenceAlignment: Pointer
9182
ReflowComments: false
92-
SortIncludes: true
93-
SortUsingDeclarations: true
83+
SeparateDefinitionBlocks: Always
84+
SortIncludes: CaseInsensitive
85+
SortUsingDeclarations: LexicographicNumeric
9486
SpaceAfterCStyleCast: true
9587
SpaceAfterTemplateKeyword: false
9688
SpaceBeforeAssignmentOperators: true
@@ -101,7 +93,7 @@ SpaceBeforeParens: ControlStatements
10193
SpaceBeforeRangeBasedForLoopColon: true
10294
SpaceInEmptyParentheses: false
10395
SpacesBeforeTrailingComments: 1
104-
SpacesInAngles: false
96+
SpacesInAngles: Never
10597
SpacesInCStyleCastParentheses: false
10698
SpacesInContainerLiterals: false
10799
SpacesInParentheses: false
@@ -110,4 +102,4 @@ StatementMacros:
110102
- Q_UNUSED
111103
- QT_REQUIRE_VERSION
112104
TabWidth: 4
113-
UseTab: Never
105+
UseTab: Never

.clang-tidy

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ Checks: >
77
modernize-*,
88
cppcoreguidelines-*,
99
concurrency-*,
10+
portability-*,
11+
readability-duplicate-include,
12+
readability-redundant-string-cstr,
13+
readability-simplify-boolean-expr,
1014
-modernize-use-trailing-return-type,
15+
-modernize-use-std-print,
1116
-cppcoreguidelines-avoid-magic-numbers,
1217
-llvm-header-guard,
1318
-readability-identifier-length,
@@ -32,7 +37,6 @@ WarningsAsErrors: >
3237
performance-trivially-destructible,
3338
bugprone-exception-escape
3439
35-
HeaderFilterRegex: '.'
40+
HeaderFilterRegex: "."
3641
AnalyzeTemporaryDtors: true
3742
FormatStyle: file
38-
User: user

.github/actions/install-dependencies/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ inputs:
99
qt_ver:
1010
description: "qt version"
1111
required: false
12-
default: "6.10.2"
12+
default: "6.11.1"
1313
type: string
1414

1515
runs:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- 要求 CMake 3.25+;使用 `cmake_minimum_required(VERSION 3.25)`
2+
- 优先使用 `target_*` 命令;仅当设置需应用于所有目标时才用全局 `add_compile_definitions`/`add_compile_options`
3+
- 禁止全局 `include_directories`/`add_definitions`(路径/定义应按目标控制)
4+
-`target_compile_features(target PRIVATE cxx_std_20)` 设置语言标准
5+
-`GNUInstallDirs` 实现可移植安装路径
6+
-`FetchContent` 或带版本约束的 `find_package`
7+
- 禁止 `file(GLOB)` 收集源文件;显式列出
8+
- 使用 `BUILD_INTERFACE`/`INSTALL_INTERFACE` 生成器表达式
9+
- 使用 `CMakePresets.json` 管理构建配置
10+
- 通过 `target_compile_options` 启用警告,而非原始标志
11+
- 使用 `cmake_policy(SET CMP0167 NEW)` 发现 Qt6 模块
12+
- 使用 `qt_standard_project_setup()` 初始化 Qt6 项目
13+
- 导出目标时设置 `NAMESPACE` 和配置文件
14+
- CI 中将警告视为错误:`-Werror`

.trae/rules/cpp-modern.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- 最低目标 C++20,工具链支持时优先 C++23
2+
-`std::span` 替代指针+长度参数对
3+
- 可恢复错误优先用 `std::expected`,而非异常
4+
-`constexpr`/`consteval` 进行编译期计算
5+
-`concepts` 约束模板,替代 SFINAE
6+
-`std::format` 替代 printf/iostream 格式化
7+
- 优先用 `std::ranges` 算法替代手写循环
8+
-`std::jthread` 替代 `std::thread`(自动 join)
9+
- 禁止裸 `new`/`delete`;用 `std::make_unique`/`std::make_shared`
10+
- 适当标记 `[[nodiscard]]``[[deprecated]]`
11+
- 用结构化绑定处理多返回值
12+
- 统一用 `=``{}` 初始化;避免 `()`
13+
-`if constexpr` 替代标签分派
14+
- 优先用 `enum class`,避免裸 `enum`

.trae/rules/cross-platform.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- 平台特定代码使用 `Q_OS_WIN`/`Q_OS_MACOS`/`Q_OS_LINUX`
2+
- 使用 `QDir::separator()``/`(Qt 会自动规范化路径)
3+
- 使用 `QStandardPaths` 获取系统路径
4+
- 使用 `QSysInfo` 进行运行时平台检测
5+
- 避免平台特定 API;必要时用 `#ifdef` 包裹
6+
- 使用 `#pragma once` 替代头文件保护宏
7+
- 使用 `Q_DECL_DEPRECATED` 标记弃用
8+
- 使用 `Q_REQUIRED_RESULT` 替代 `[[nodiscard]]`
9+
- 使用 `Q_LIKELY`/`Q_UNLIKELY` 进行分支提示
10+
- 使用 `qint64`/`qint32` 等可移植整数类型
11+
- 避免编译器特定 `#pragma`;使用 `Q_*`
12+
- CI 中在所有目标平台上测试
13+
- 使用 `QFile`/`QSaveFile` 替代原始文件 API

.trae/rules/error-handling.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- 异常仅用于不可恢复情况,不用于控制流
2+
- 可恢复错误使用 `std::expected<T, E>`
3+
- 跨边界错误报告使用 `std::error_code`
4+
- OS 级错误使用 `std::system_error`
5+
- 按常量引用捕获:`catch (const std::exception& e)`
6+
- 移动构造函数和析构函数标记 `noexcept`
7+
- 调试断言使用 `Q_ASSERT`
8+
- 不可达代码使用 `Q_UNREACHABLE()`
9+
- 日志使用 `qWarning()`/`qCritical()`
10+
- 文档中注明异常保证:基本、强、不抛出
11+
- 永不返回的函数标记 `[[noreturn]]`
12+
- 跨线程错误传播使用 `QException`

.trae/rules/memory-safety.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- 独占所有权使用 `std::unique_ptr`
2+
- 仅在需要共享所有权时使用 `std::shared_ptr`
3+
- 使用 `std::weak_ptr` 打破循环引用
4+
- 使用 `std::make_unique`/`std::make_shared` 替代 `new`
5+
- Qt 风格 RAII 可使用 `QScopedPointer`
6+
- 使用 `std::vector` 替代 `new[]`
7+
- 非拥有视图使用 `std::span`
8+
- 只读字符串参数使用 `std::string_view`
9+
- C++ 中禁止使用 `malloc`/`free`
10+
- QObject 弱引用使用 `QPointer`
11+
- 延迟删除使用 `QObject::deleteLater()`
12+
- 裸指针仅作非拥有视图;禁止作为所有者
13+
- 互斥锁 RAII 使用 `std::lock_guard`/`std::unique_lock`

.trae/rules/qml-best-practices.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
- 使用 Qt 6 QML 无版本导入:`import QtQuick`
2+
- 根元素优先用 `Item`;避免用 `Rectangle` 作容器
3+
- 使用 `required property` 定义显式接口
4+
- 慎用 `Component.onCompleted`;优先使用属性绑定
5+
-`QML_ELEMENT` 注册 C++ 类型,替代 `qmlRegisterType`
6+
- 列表使用 `ListView` 配合 `model``delegate`
7+
- 使用 `Loader` 延迟加载重型组件
8+
- 仅在需要动态重绑定时使用 `Qt.binding()`
9+
- 分离模型(C++)与视图(QML);遵循 MVC 模式
10+
- 避免命令式 JS;使用属性绑定
11+
- CI 中运行 `qmllint``qmlformat`
12+
- 使用 `property alias` 暴露内部组件
13+
- 全局对象优先用 `QML_SINGLETON`
14+
- 结构化数据使用 `QML_STRUCTURED_VALUE`

.trae/rules/qt6-best-practices.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- 优先使用 Qt 6 API,避免 Qt 5 遗留接口
2+
- 使用 `QString` 字面量:`u"s..."_s`
3+
- 信号槽使用函数指针语法,禁止 `SIGNAL()`/`SLOT()` 字符串形式
4+
-`QML_ELEMENT`/`QML_NAMED_ELEMENT` 将 C++ 类型暴露给 QML
5+
-`QProperty`/`QBindable` 实现响应式绑定
6+
-`std::make_unique` 或 Qt 父对象所有权;禁止裸 `new`
7+
- 不可拷贝类型使用 `Q_DISABLE_COPY_MOVE`
8+
- 优先用 `QMetaObject::invokeMethod` 的 functor 重载
9+
- 槽函数中禁止阻塞调用;使用 `QtConcurrent``QThreadPool`
10+
- 异步操作使用 `QFutureWatcher``QCoro`
11+
- 发射信号时使用 `emit` 关键字
12+
- 元数据反射优先用 `Q_ENUM`/`Q_FLAG`
13+
- 使用 `qWarning()`/`qInfo()`/`qCritical()` 分类日志

0 commit comments

Comments
 (0)