Skip to content

fix: adapt checkbox state handling for Qt6 - #775

Open
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:fix-qt6-qcheckbox-checkStateChanged
Open

fix: adapt checkbox state handling for Qt6#775
18202781743 wants to merge 1 commit into
linuxdeepin:masterfrom
18202781743:fix-qt6-qcheckbox-checkStateChanged

Conversation

@18202781743

@18202781743 18202781743 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Qt6 中 QCheckBox 的复选状态信号签名由 stateChanged(int) 变为 checkStateChanged(Qt::CheckState)。dtkwidget 中仍有 3 处 Qt6 分支使用旧式 int 参数:

  1. dprintpreviewdialog.cpp duplex 复选框使用字符串式 SIGNAL(checkStateChanged(int)),在 Qt6 下匹配不到信号,产生 QObject::connect: No such signal QCheckBox::checkStateChanged(int) 警告且连接静默失败。
  2. dprintpreviewdialog.cpp sidebyside 复选框 lambda 参数为 intstatus == 0 魔法数字。
  3. dsettingswidgetfactory.cpp 复选框工厂 lambda 参数为 int

本次统一改为 Qt6 正确的 Qt::CheckState 类型,并将 duplex 的字符串式连接改为函数指针 lambda 连接。

Changes

  • dprintpreviewdialog.cpp: duplex 复选框改为 &DCheckBox::checkStateChanged + lambda(显式 int(state) 转换传给 _q_checkStateChanged);sidebyside 复选框参数改 Qt::CheckStatestatus == 0 改为 status == Qt::Unchecked
  • dsettingswidgetfactory.cpp: 复选框工厂 lambda 参数改为 Qt::CheckState

Qt5 分支(stateChanged(int))保持不变。已用 Qt6 构建验证(dtk6widget 100% 编译通过,无新增告警)。

Test

  • 打印预览对话框切换"并排显示"与"双面打印"复选框,验证行为正常、无 No such signal 警告
  • 设置项工厂复选框勾选/取消正确写回 DSettingsOption
  • Qt5 构建回归无变化

Summary by Sourcery

Correct checkbox state handling across Qt6 widget integrations while maintaining Qt5 compatibility.

Bug Fixes:

  • Fix Qt6 checkbox signal handling in print preview and settings widgets so checkbox changes connect and update reliably without invalid-signal warnings.

Enhancements:

  • Use Qt's typed checkbox state handling and explicit unchecked-state comparison while preserving Qt5 behavior.

@sourcery-ai

sourcery-ai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The 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 handling

sequenceDiagram
    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)
Loading

File-Level Changes

Change Details Files
Use the Qt6 checkbox signal signature and enum type throughout affected connections.
  • Change Qt6 side-by-side checkbox lambdas to accept Qt::CheckState.
  • Replace the unchecked-state magic number with Qt::Unchecked.
  • Update the settings widget factory lambda to accept Qt::CheckState and preserve boolean value mapping.
src/widgets/dprintpreviewdialog.cpp
src/widgets/dsettingswidgetfactory.cpp
Replace the failing Qt6 string-based duplex signal connection with a typed connection and compatibility conversion.
  • Connect DCheckBox::checkStateChanged via function pointer and lambda.
  • Convert Qt::CheckState explicitly to int before invoking the existing handler.
  • Leave Qt5 stateChanged(int) connections unchanged under conditional compilation.
src/widgets/dprintpreviewdialog.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@18202781743
18202781743 requested review from BLumia and mhduiy August 26, 2026 07:14

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/widgets/dsettingswidgetfactory.cpp Outdated
@18202781743
18202781743 force-pushed the fix-qt6-qcheckbox-checkStateChanged branch 2 times, most recently from 759c47e to b474da1 Compare August 26, 2026 08:09
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控件
@18202781743
18202781743 force-pushed the fix-qt6-qcheckbox-checkStateChanged branch from b474da1 to 918cf5a Compare August 26, 2026 08:46
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants