Skip to content

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Jan 27, 2026

  • 在 CMakeLists.txt 中为 Qt6 正确配置 OpenGL 和 OpenGLWidgets 依赖项
  • 更新 DeviceInput.cpp 中的 Qt 版本兼容性代码,使用条件编译处理字符串截取方法差异

Log: Fix Qt5 build failed issue.

Summary by Sourcery

Fix Qt5 build failures by adjusting Qt component configuration and making Qt version-specific string handling compatible with both Qt5 and Qt6.

Bug Fixes:

  • Resolve Qt5 build errors by restoring OpenGL linkage in the Qt components list while keeping Qt6 support.
  • Fix PID extraction from VID_PID strings by using version-appropriate Qt APIs for substring operations across Qt5 and Qt6.

- 在 CMakeLists.txt 中为 Qt6 正确配置 OpenGL 和 OpenGLWidgets 依赖项
- 更新 DeviceInput.cpp 中的 Qt 版本兼容性代码,使用条件编译处理字符串截取方法差异

Log: Fix Qt5 build failed issue.
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 27, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Qt component configuration in CMake for proper OpenGL dependencies in Qt6 and fixes Qt5 build issues by adding Qt-version-specific string slicing for PID extraction in DeviceInput.

Class diagram for DeviceInput with Qt-version-specific PID extraction

classDiagram
    class DeviceInput {
        QString m_VID_PID
        QString m_VID
        QString m_PID
        bool m_Enable
        void setInfoFromHwinfo(QMap<QString,QString> mapInfo)
    }
Loading

File-Level Changes

Change Details Files
Make PID extraction in DeviceInput Qt-version compatible.
  • Use conditional compilation on QT_VERSION to select appropriate QString API for extracting the PID substring.
  • For Qt6 builds, use last(4) to get the last four characters of m_VID_PID.
  • For Qt5 builds, use right(4) to get the last four characters of m_VID_PID when size is 10.
deepin-devicemanager/src/DeviceManager/DeviceInput.cpp
Fix Qt component list for Qt6 to correctly include OpenGL and OpenGLWidgets.
  • Remove unconditional OpenGL from the base QT_COMPONENTS list that is shared by all Qt versions.
  • Under Qt6 (QT_VERSION_MAJOR EQUAL 6), append both OpenGL and OpenGLWidgets to QT_COMPONENTS so OpenGL is still available in Qt6 builds.
  • Leave Qt5 path unchanged except for inheriting the fact that OpenGL is no longer in the common list.
deepin-devicemanager/CMakeLists.txt

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

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, and left some high level feedback:

  • The version-specific PID extraction logic using preprocessor checks might be better centralized in a small helper (e.g., a QString compatibility utility) to avoid scattering Qt-version conditionals throughout the codebase.
  • In CMakeLists.txt, the comment 'Add components only available in Qt6' no longer matches the logic now that OpenGL (also available in Qt5) is appended there; consider updating the comment or moving OpenGL back into the common component list for clarity.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The version-specific PID extraction logic using preprocessor checks might be better centralized in a small helper (e.g., a QString compatibility utility) to avoid scattering Qt-version conditionals throughout the codebase.
- In CMakeLists.txt, the comment 'Add components only available in Qt6' no longer matches the logic now that `OpenGL` (also available in Qt5) is appended there; consider updating the comment or moving `OpenGL` back into the common component list for clarity.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/DeviceManager/DeviceInput.cpp:117` </location>
<code_context>
         if (m_VID_PID.size() == 10) {
             m_VID = m_VID_PID.mid(2, 4);
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
             m_PID = m_VID_PID.last(4);
+#else
+            m_PID = m_VID_PID.right(4);
</code_context>

<issue_to_address>
**suggestion:** Consider using a version-independent substring API to avoid preprocessor branching for PID extraction.

Given `m_VID_PID.size() == 10` is already validated, you can do `m_PID = m_VID_PID.mid(6, 4);` instead. This works in both Qt5 and Qt6, so you can drop the `#if QT_VERSION` block and keep the assignment in a single line.
</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.

@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改主要涉及构建系统配置、源代码兼容性处理以及版本控制忽略文件的更新。以下是对这三个文件变更的详细审查和改进建议:

1. .gitignore 修改审查

变更内容:添加了 .cache/ 目录到忽略列表。

审查意见

  • 语法逻辑:正确。.gitignore 的语法允许忽略目录。
  • 代码质量:良好。将缓存目录加入忽略列表是标准做法,避免将构建生成的临时文件或缓存文件提交到仓库,保持仓库整洁。
  • 代码安全:无直接影响。
  • 改进建议:无。

2. CMakeLists.txt 修改审查

变更内容

  1. QT_COMPONENTS 列表中移除了 OpenGL
  2. 在 Qt6 的条件判断中,显式添加了 OpenGLOpenGLWidgets

审查意见

  • 语法逻辑:逻辑上存在潜在风险。
    • 原代码中 OpenGL 在公共列表中,意味着 Qt5 和 Qt6 都会尝试链接它。
    • 新代码将 OpenGL 从公共列表移除,仅在 Qt6 分支添加。这意味着 Qt5 构建将不再链接 OpenGL 模块
    • 如果项目中使用了 QOpenGL* 类(如 QOpenGLWidgetQOpenGLFunctions),在 Qt5 中这些类通常位于 Qt5::OpenGL 模块中(QtWidgets 依赖它,但有时需要显式链接)。在 Qt6 中,GUI 类位于 QtGui,而 OpenGL widget 类位于 QtOpenGLWidgets
    • 如果代码中使用了 Qt5 的 QOpenGLWidget,移除 OpenGL 组件可能会导致链接错误。
  • 代码质量:意图可能是区分 Qt5 和 Qt6 对 OpenGL 的处理方式,但修改可能导致 Qt5 环境下的编译失败。
  • 代码性能:无影响。
  • 代码安全:无影响。

改进建议
请确认项目代码是否在 Qt5 环境下直接使用了 QOpenGLWidgetQOpenGLFunctions

  • 如果是,Qt5 仍然需要 OpenGL 组件。建议的修改如下:
# 基础组件
set(QT_COMPONENTS
    Svg
    SvgWidgets
    Xml
    Core
)

if(${QT_VERSION_MAJOR} EQUAL 6)
    # Qt6: OpenGL 相关功能分散在 QtGui (基础), QtOpenGL, QtOpenGLWidgets
    list(APPEND QT_COMPONENTS OpenGL OpenGLWidgets)
else()
    # Qt5: 保留 SvgWidgets,并确保包含 OpenGL (如果代码中使用了 QOpenGL*)
    # 注意:Qt5 的 Widgets 通常隐式链接 OpenGL,但显式声明更安全
    list(APPEND QT_COMPONENTS OpenGL) 
    # 如果确定不需要 SvgWidgets 在 Qt5 中存在,保留原有的 REMOVE_ITEM 逻辑
    # list(REMOVE_ITEM QT_COMPONENTS SvgWidgets) 
endif()

3. DeviceInput.cpp 修改审查

变更内容:使用 Qt 版本宏 QT_VERSION_CHECK 区分 QString::last() (Qt6) 和 QString::right() (Qt5)。

审查意见

  • 语法逻辑存在严重问题
    • QT_VERSION 是一个预处理器宏,展开后是一个整数(例如 Qt 5.15.2 是 0x050F02)。
    • QT_VERSION_CHECK(6, 0, 0) 展开后也是一个整数(0x060000)。
    • 代码写为 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0),这在预处理阶段进行整数比较,逻辑是正确的。
    • 但是QT_VERSION 代表的是编译时 Qt 库的版本,而不是代码运行时检测到的版本。
    • 如果这个项目需要在同一个二进制文件中兼容 Qt5 和 Qt6(即使用 Qt5 编译时能跑,用 Qt6 编译时也能跑),这种写法是正确的。
    • 如果项目意图是:使用 Qt5 编译出来的程序,在运行时如果检测到系统是 Qt6 环境就调用新 API,这种写法是错误的。预处理器在编译时就决定了分支,无法在运行时动态切换。
    • 通常情况下,Qt 程序是针对特定版本的 Qt 编译的,因此这种预处理器判断是标准的迁移做法。
  • 代码质量:符合 Qt 跨版本迁移的最佳实践。QString::right(n) 在 Qt6 中被弃用(虽然仍可用),QString::last(n) 是 Qt6 推荐的新 API。
  • 代码性能:无影响。
  • 代码安全:无影响。

改进建议
目前的写法是正确的,但为了更严谨,建议使用 QT_VERSION_MAJOR 宏(如果 Qt 版本较新支持),或者保持现状。这是标准的代码迁移方式。

总结

  1. .gitignore: 修改合理。
  2. CMakeLists.txt: 高风险。移除 Qt5 的 OpenGL 依赖可能导致链接错误。请务必在 Qt5 环境下测试编译,确认是否仍需要 OpenGL 模块。如果代码中使用了 QOpenGLWidget,Qt5 通常需要链接 OpenGL
  3. DeviceInput.cpp: 修改合理且正确,符合 Qt5 到 Qt6 的代码迁移规范。

综合建议
重点检查 CMakeLists.txt 中关于 OpenGL 的依赖。如果代码逻辑确实不再依赖 Qt5 的 OpenGL 模块(例如完全移除了 QOpenGLWidget 的使用,改用了纯 QWidget 或其他方案),则该修改是安全的;否则,建议回退或调整 CMake 逻辑,确保 Qt5 也能正确链接所需的库。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

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

@re2zero
Copy link
Contributor Author

re2zero commented Jan 27, 2026

/merge

@deepin-bot deepin-bot bot merged commit ad44a57 into linuxdeepin:master Jan 27, 2026
18 checks passed
@re2zero re2zero deleted the bugfix branch January 27, 2026 12:25
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