Skip to content

fix: resolve Qt6 compilation warnings and deprecations#519

Merged
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master
Aug 18, 2025
Merged

fix: resolve Qt6 compilation warnings and deprecations#519
18202781743 merged 1 commit into
linuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Copy Markdown
Contributor

@18202781743 18202781743 commented Aug 18, 2025

  1. Added conditional compilation for Qt5/Qt6 compatibility
  2. Replaced deprecated qAsConst with std::as_const for Qt6
  3. Added D_IGNORE_DEPRECATIONS flag to suppress deprecation warnings
  4. Fixed static_assert removal in dbackdropnode.cpp
  5. Added missing Q_UNUSED macro in dquickimageprovider.cpp
  6. Cleaned up initialization syntax in dquickwindow_p.h
  7. Fixed platform check from IsTreelandPlatform to IsWaylandPlatform
  8. Improved memory management in AppLoaderSimulator destructor

Influence:

  1. Verify application builds successfully with both Qt5 and Qt6
  2. Test high DPI functionality on both Qt versions
  3. Validate blur effects and window management features
  4. Check all QML components render correctly
  5. Test palette and color selector functionality
  6. Verify shadow provider image generation
  7. Test settings container and group visibility

fix: 解决Qt6编译警告和废弃API问题

  1. 添加Qt5/Qt6兼容性条件编译
  2. 将废弃的qAsConst替换为std::as_const(Qt6)
  3. 添加D_IGNORE_DEPRECATIONS标志抑制废弃API警告
  4. 修复dbackdropnode.cpp中移除的static_assert
  5. 在dquickimageprovider.cpp中添加缺失的Q_UNUSED宏
  6. 清理dquickwindow_p.h中的初始化语法
  7. 将平台检查从IsTreelandPlatform修正为IsWaylandPlatform
  8. 改进AppLoaderSimulator析构函数的内存管理

Influence:

  1. 验证应用在Qt5和Qt6下都能成功构建
  2. 测试两个Qt版本下的高DPI功能
  3. 验证模糊效果和窗口管理功能
  4. 检查所有QML组件是否正确渲染
  5. 测试调色板和颜色选择器功能
  6. 验证阴影提供者图像生成
  7. 测试设置容器和组可见性

Summary by Sourcery

Resolve Qt6 compilation warnings and deprecations by adding Qt version guards, replacing deprecated APIs, suppressing warnings, and applying ancillary fixes to maintain compatibility with both Qt5 and Qt6.

Bug Fixes:

  • Add missing Q_UNUSED macro in dquickimageprovider.cpp to suppress unused parameter warnings
  • Remove misplaced static_assert and unused variable in dbackdropnode.cpp
  • Correct platform check to IsWaylandPlatform instead of IsTreelandPlatform
  • Improve memory cleanup in AppLoaderSimulator destructor

Enhancements:

  • Add conditional compilation for Qt5/Qt6 to use std::as_const under Qt6 and qAsConst under Qt5
  • Clean up initialization syntax for DPlatformHandle enum members in dquickwindow_p.h
  • Include qglobal for Qt version checks
  • Remove inline specifiers from yOffset methods in dquickwaterprogressattribute_p.h

Build:

  • Define D_IGNORE_DEPRECATIONS in CMakeLists to suppress Qt deprecation warnings

@18202781743 18202781743 requested review from BLumia and mhduiy August 18, 2025 04:15
deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 18, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#519
Copy link
Copy Markdown

@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 there - I've reviewed your changes and they look great!


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.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Aug 18, 2025

Reviewer's Guide

This PR implements Qt6 compatibility by wrapping container iterations in QT_VERSION checks to switch between qAsConst and std::as_const, adds deprecation suppression flags, removes obsolete code constructs, refines initialization syntax, corrects a platform attribute check, and improves memory handling in the loader tests.

Class diagram for SettingsContainer and SettingsGroup iteration changes

classDiagram
    class SettingsContainer {
        +QVector<SettingsGroup *> groupList() const
        +bool groupVisible(const QString &key) const
        +void resetSettings()
        -QVector<SettingsGroup *> m_groups
    }
    class SettingsGroup {
        +void setBackground(QQmlComponent *background)
        +void setConfig(QObject *config)
        -QList<SettingsGroup *> m_children
        -QList<Option *> m_options
    }
    SettingsContainer "1" *-- "*" SettingsGroup : m_groups
    SettingsGroup "1" *-- "*" SettingsGroup : m_children
    SettingsGroup "1" *-- "*" Option : m_options
Loading

Class diagram for DQuickControlColorSelector iteration changes

classDiagram
    class DQuickControlColorSelector {
        +void findAndSetControlParent()
        +void recvPaletteColorChanged()
        +void onPaletteDestroyed()
        -QList<QMetaObject::Connection> m_itemParentChangeConnections
        -QMap<QString, DQuickControlPalette*> m_palettes
    }
Loading

Class diagram for WaterPopAttribute method signature changes

classDiagram
    class WaterPopAttribute {
        +qreal sizeRatio() const
        +qreal yOffset() const
        +void setYOffset(qreal offset)
        +signal xSpeedChanged()
    }
Loading

Class diagram for DAppLoaderPrivate iteration and memory management changes

classDiagram
    class DAppLoaderPrivate {
        +bool createObjects(const char *propertyName)
        +void createChildComponents()
        +void _q_onComponentProgressChanged()
    }
Loading

Class diagram for DataManager and RhiNode static_assert removal

classDiagram
    class DataManager {
        +static DataManagerPointer<Derive> resolve(const DataManagerPointer<Derive> &other, QQuickWindow *owner)
    }
    class RhiNode {
        +void render()
    }
Loading

Class diagram for DQuickShadowProvider requestImage change

classDiagram
    class DQuickShadowProvider {
        +QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize)
    }
Loading

File-Level Changes

Change Details Files
Introduce Qt5/Qt6 conditional compilation for container iterations
  • Wrap loops with #if QT_VERSION checks
  • Use std::as_const for Qt6 and fallback to qAsConst for Qt5
  • Apply this pattern in settingscontainer, controlpalette, dquickwindow and dapploader
src/private/dsettingscontainer.cpp
src/private/dquickcontrolpalette.cpp
src/dquickwindow.cpp
src/dapploader.cpp
Suppress deprecation warnings via build flags
  • Define D_IGNORE_DEPRECATIONS in main and Qt6 CMake targets
  • Apply target_compile_definitions to both src/CMakeLists.txt and qt6/src/CMakeLists.txt
src/CMakeLists.txt
qt6/src/CMakeLists.txt
Remove deprecated constructs and add missing macros
  • Eliminate obsolete static_assert in dbackdropnode.cpp
  • Delete redundant rhi->rhi call
  • Insert Q_UNUSED macro for unused parameters in dquickimageprovider.cpp
  • Remove inline specifiers in waterprogressattribute header
src/private/dbackdropnode.cpp
src/private/dquickimageprovider.cpp
src/private/dquickwaterprogressattribute_p.h
Fix incorrect platform attribute check
  • Change DGuiApplicationHelper::IsTreelandPlatform to IsWaylandPlatform
src/dquickwindow.cpp
Tidy includes and initialization syntax
  • Add #include <qglobal.h> in dquickwindow.cpp
  • Switch to brace initialization for explicitEffectScene and explicitEffectType in dquickwindow_p.h
src/dquickwindow.cpp
src/private/dquickwindow_p.h
Improve memory management in AppLoaderSimulator test
  • Replace manual take() call with automatic cleanup via QScopedPointer in the destructor
tests/ut_dapploader.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

1. Added conditional compilation for Qt5/Qt6 compatibility
2. Replaced deprecated qAsConst with std::as_const for Qt6
3. Added D_IGNORE_DEPRECATIONS flag to suppress deprecation warnings
4. Fixed static_assert removal in dbackdropnode.cpp
5. Added missing Q_UNUSED macro in dquickimageprovider.cpp
6. Cleaned up initialization syntax in dquickwindow_p.h
7. Fixed platform check from IsTreelandPlatform to IsWaylandPlatform
8. Improved memory management in AppLoaderSimulator destructor

Influence:
1. Verify application builds successfully with both Qt5 and Qt6
2. Test high DPI functionality on both Qt versions
3. Validate blur effects and window management features
4. Check all QML components render correctly
5. Test palette and color selector functionality
6. Verify shadow provider image generation
7. Test settings container and group visibility

fix: 解决Qt6编译警告和废弃API问题

1. 添加Qt5/Qt6兼容性条件编译
2. 将废弃的qAsConst替换为std::as_const(Qt6)
3. 添加D_IGNORE_DEPRECATIONS标志抑制废弃API警告
4. 修复dbackdropnode.cpp中移除的static_assert
5. 在dquickimageprovider.cpp中添加缺失的Q_UNUSED宏
6. 清理dquickwindow_p.h中的初始化语法
7. 将平台检查从IsTreelandPlatform修正为IsWaylandPlatform
8. 改进AppLoaderSimulator析构函数的内存管理

Influence:
1. 验证应用在Qt5和Qt6下都能成功构建
2. 测试两个Qt版本下的高DPI功能
3. 验证模糊效果和窗口管理功能
4. 检查所有QML组件是否正确渲染
5. 测试调色板和颜色选择器功能
6. 验证阴影提供者图像生成
7. 测试设置容器和组可见性
deepin-ci-robot added a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 18, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#519
@deepin-ci-robot
Copy link
Copy Markdown
Contributor

deepin pr auto review

根据提供的代码差异,我来分析一下代码的质量、逻辑、性能和安全性,并提出改进建议:

1. Qt版本兼容性改进

优点:

  • 代码中正确处理了Qt5和Qt6的版本差异,使用#if QT_VERSION条件编译来确保兼容性
  • 在需要的地方使用了Qt6的新特性std::as_const替代qAsConst

改进建议:

  • main.cpp中添加了高DPI支持的条件编译,但建议添加更详细的注释说明为什么需要这个条件编译
  • 建议将版本相关的宏定义集中到一个头文件中,便于维护

2. 代码安全性改进

优点:

  • DQuickShadowProvider::requestImage中正确使用了Q_UNUSED标记未使用的参数
  • DQuickWindowAttachedPrivate中使用了初始化列表语法进行成员初始化,提高了安全性

改进建议:

  • DQuickWindowAttached::isEnabled中,将IsTreelandPlatform改为IsWaylandPlatform,建议添加注释说明这个变更的原因
  • dbackdropnode.cpp中移除了static_assert和未使用的rhi变量,这是好的清理工作

3. 代码质量改进

优点:

  • WaterPopAttribute中的inline关键字移除,遵循了现代C++的最佳实践
  • 使用了更现代的初始化语法({})来初始化成员变量

改进建议:

  • dsettingscontainer.cpp中,大量重复的#if QT_VERSION条件编译块,建议提取为一个宏或辅助函数,减少代码重复
  • AppLoaderSimulator析构函数中,注释说明使用QScopedPointer自动管理内存,这是很好的改进

4. 性能优化建议

优点:

  • 使用std::as_constqAsConst来避免不必要的拷贝,这是好的性能优化
  • DAppLoaderPrivate中使用了常量引用传递对象

改进建议:

  • DQuickWindowAttachedPrivate::_q_updateBlurAreaForWindow中,可以考虑使用const auto&来避免不必要的拷贝
  • SettingsContainer::groupList中,使用了std::reverse来保持顺序,可以考虑使用更高效的数据结构来避免这个操作

5. 其他建议

  1. 代码组织:

    • 建议将版本相关的代码集中管理
    • 考虑将重复的Qt版本检查逻辑提取为宏或辅助函数
  2. 注释:

    • 对重要的版本相关变更添加详细注释
    • 对平台相关的判断添加说明性注释
  3. 测试:

    • 建议添加针对不同Qt版本的单元测试
    • 确保所有平台相关的功能都经过充分测试

总体来说,这些代码差异展示了对Qt5和Qt6兼容性的良好处理,代码质量较高,但仍有一些可以改进的地方,特别是在代码重复和性能优化方面。

@deepin-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, mhduiy

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

@18202781743 18202781743 merged commit a5dba3e into linuxdeepin:master Aug 18, 2025
19 of 20 checks passed
18202781743 pushed a commit to linuxdeepin/dtk6declarative that referenced this pull request Aug 18, 2025
Synchronize source files from linuxdeepin/dtkdeclarative.

Source-pull-request: linuxdeepin/dtkdeclarative#519
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