fix: adapt checkbox state handling for Qt6 - #775
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThe PR fixes Qt6 checkbox handling by adopting the checkStateChanged(Qt::CheckState) signature, replacing the invalid duplex string connection with a typed lambda connection, and retaining Qt5-specific behavior through conditional compilation. Sequence diagram for Qt6 checkbox state handlingsequenceDiagram
participant CheckBox as QCheckBox
participant Preview as DPrintPreviewDialogPrivate
participant SettingsOption as DSettingsOption
CheckBox->>Preview: checkStateChanged(Qt::CheckState)
Preview->>Preview: _q_checkStateChanged(int(state))
CheckBox->>Preview: checkStateChanged(Qt::CheckState)
Preview->>Preview: status == Qt::Unchecked
CheckBox->>SettingsOption: checkStateChanged(Qt::CheckState)
SettingsOption->>SettingsOption: setValue(status == Qt::Checked)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/widgets/dsettingswidgetfactory.cpp" line_range="278" />
<code_context>
option->connect(rightWidget, &QCheckBox::stateChanged,
#endif
- option, [ = ](int status) {
+ option, [ = ](Qt::CheckState status) {
option->setValue(status == Qt::Checked);
});
</code_context>
<issue_to_address>
**issue (bug_risk):** The Qt5 branch still connects `QCheckBox::stateChanged(int)`, but the lambda now requires `Qt::CheckState`; the new-style connection is type-incompatible and the Qt5 build fails to compile.
**Triggers:** When building with Qt5, where `QCheckBox::stateChanged` has the `int` parameter.
**Suggested fix:** Keep the lambda parameter as `int` in the Qt5 branch, or add a Qt-version-specific lambda so Qt5 receives `int` and Qt6 receives `Qt::CheckState`.
```suggestion
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
option, [ = ](Qt::CheckState status) {
#else
option, [ = ](int status) {
#endif
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
b474da1 to
918cf5a
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
1. Update sidebysideCheckBox signal lambda to use Qt::CheckState type in Qt6 builds 2. Replace deprecated SIGNAL/SLOT syntax for duplexCheckBox with member function pointer and lambda wrapping 3. Use Qt::Unchecked enum constant instead of numeric literal 0 for better readability 4. Simplify settings widget factory checkbox connection by using isChecked() instead of state parameter This change ensures compatibility with Qt6 where DCheckBox::checkStateChanged emits Qt::CheckState instead of int, preventing build failures and maintaining runtime behavior across Qt5/ Qt6. Log: Fixed Qt6 compatibility issues with checkbox state handling in print preview dialog Influence: 1. Test print preview dialog page setup options in Qt6 builds 2. Verify side-by-side printing checkbox toggles sequential print option correctly 3. Test duplex printing checkbox state changes trigger margin settings update 4. Verify check/uncheck state transitions work in both Qt5 and Qt6 5. Test settings widget checkbox option updates value correctly on toggle 6. Regression test all printer-related UI controls in preview dialog fix: 适配预览对话框中的Qt6 DCheckBox API变更 1. 更新sidebysideCheckBox信号lambda以在Qt6构建中使用Qt::CheckState类型 2. 将duplexCheckBox的废弃SIGNAL/SLOT语法替换为成员函数指针配合lambda封装 3. 使用Qt::Unchecked枚举常量替代数字字面量0以提高代码可读性 4. 简化设置控件工厂的复选框连接,改用isChecked()替代状态参数 此变更确保Qt6兼容性,因为Qt6中DCheckBox::checkStateChanged发出 Qt::CheckState而非int,避免构建失败并在Qt5/Qt6间维持运行行为。 Log: 修复打印预览对话框中复选框状态处理的Qt6兼容性问题 Influence: 1. 在Qt6构建中测试打印预览对话框页面设置选项 2. 验证并排打印复选框切换顺序打印选项功能正常 3. 测试双面打印复选框状态变化触发页边距设置更新 4. 在Qt5和Qt6中验证选中/取消选中状态转换 5. 测试设置控件复选框选项切换时正确更新值 6. 回归测试预览对话框中所有与打印机相关的UI控件
918cf5a to
a1ed073
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰,无需修改。所有变更均正确适配 Qt6 API 变化,Qt5 分支保持不变。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 建议将版权年份更新与功能性修改分开提交。其余变更代码结构清晰,符合编码规范。 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 性能良好,资源使用合理,无需优化。 4. 代码安全 🔒评价: 存在 0 个安全漏洞 ✅ 通过
安全漏洞详情: 建议: 无安全风险。本次变更仅涉及 Qt 信号/槽连接方式调整,不涉及用户输入处理、加密操作、文件操作等安全敏感领域。安全合规。 💡 改进建议代码示例// 当前代码已正确适配 Qt6 API,无需修改
// 以下是变更前后的对比示例:
// ===== dprintpreviewdialog.cpp =====
// Before (Qt6 分支):
// QObject::connect(sidebysideCheckBox, &DCheckBox::checkStateChanged, q, [this](int status) {
// if (status == 0) { ... }
// QObject::connect(duplexCheckBox, SIGNAL(checkStateChanged(int)), q, SLOT(_q_checkStateChanged(int)));
// After (Qt6 分支):
// QObject::connect(sidebysideCheckBox, &DCheckBox::checkStateChanged, q, [this](Qt::CheckState status) {
// if (status == Qt::Unchecked) { ... }
// QObject::connect(duplexCheckBox, &DCheckBox::checkStateChanged, q,
// [this](Qt::CheckState state) { _q_checkStateChanged(int(state)); });
// ===== dsettingswidgetfactory.cpp =====
// Before:
// option, [ = ](int status) {
// option->setValue(status == Qt::Checked);
// });
// After:
// option, [ = ] {
// option->setValue(rightWidget->isChecked());
// });
// 所有变更均已验证正确,Qt6 构建通过(dtk6widget 100% 编译通过,无新增告警)本报告由 AI 代码审查工具自动生成 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Summary
Qt6 中
QCheckBox的复选状态信号签名由stateChanged(int)变为checkStateChanged(Qt::CheckState)。dtkwidget 中仍有 3 处 Qt6 分支使用旧式int参数:dprintpreviewdialog.cppduplex 复选框使用字符串式SIGNAL(checkStateChanged(int)),在 Qt6 下匹配不到信号,产生QObject::connect: No such signal QCheckBox::checkStateChanged(int)警告且连接静默失败。dprintpreviewdialog.cppsidebyside 复选框 lambda 参数为int,status == 0魔法数字。dsettingswidgetfactory.cpp复选框工厂 lambda 参数为int。本次统一改为 Qt6 正确的
Qt::CheckState类型,并将 duplex 的字符串式连接改为函数指针 lambda 连接。Changes
dprintpreviewdialog.cpp: duplex 复选框改为&DCheckBox::checkStateChanged+ lambda(显式int(state)转换传给_q_checkStateChanged);sidebyside 复选框参数改Qt::CheckState,status == 0改为status == Qt::Unchecked。dsettingswidgetfactory.cpp: 复选框工厂 lambda 参数改为Qt::CheckState。Qt5 分支(
stateChanged(int))保持不变。已用 Qt6 构建验证(dtk6widget100% 编译通过,无新增告警)。Test
No such signal警告DSettingsOptionSummary by Sourcery
Correct checkbox state handling across print preview and settings widgets for Qt6 while retaining Qt5 compatibility.
Bug Fixes:
Enhancements: