Skip to content

Conversation

@BLumia
Copy link
Member

@BLumia BLumia commented Aug 28, 2025

确保 Qt 6.9.2 可构建. 相关 Qt 变动:

qt/qtbase@a676ac0

确保 Qt 6.9.2 可构建. 相关 Qt 变动:

qt/qtbase@a676ac0

Log:
@BLumia BLumia requested a review from 18202781743 August 28, 2025 09:29
deepin-ci-robot added a commit to linuxdeepin/qt6integration that referenced this pull request Aug 28, 2025
Synchronize source files from linuxdeepin/qt5integration.

Source-pull-request: linuxdeepin/qt5integration#280
@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

这段代码审查如下:

  1. 代码逻辑问题:
  • 代码中使用了条件编译来处理不同Qt版本的API差异,这是正确的做法。
  • 但是在Qt 6.9.2及以上版本中,使用了fromNativeWindowGeometry函数,而在其他版本中使用了fromNativePixels函数,这可能会导致不同版本间的行为不一致。
  1. 代码质量问题:
  • 代码格式不够规范,缩进不一致,使得代码可读性较差。
  • 注释风格不统一,有些行有注释,有些行没有。
  • 代码中存在空行过多的问题,影响代码的紧凑性和可读性。
  1. 代码性能问题:
  • 在每次窗口更新时都会调用w->handle()->geometry()两次,这可能会影响性能,应该将其结果存储在变量中复用。
  • 条件判断if (w->property(DNOT_UPDATE_WINDOW_GEOMETRY).toBool())在每次窗口更新时都会执行,如果这个属性很少变化,可以考虑缓存这个值。
  1. 代码安全问题:
  • 代码中直接使用了w->handle(),但没有检查handle()是否为nullptr,这可能会导致空指针解引用。
  • 在使用fromNativeWindowGeometryfromNativePixels时,没有检查它们的返回值是否有效。

改进建议:

static void updateWindowGeometry(QWindow *w)
{
    if (!w || !w->handle()) {
        return;
    }

    if (w->property(DNOT_UPDATE_WINDOW_GEOMETRY).toBool()) {
        const QRect nativeGeometry = w->handle()->geometry();
        
        #if QT_VERSION >= QT_VERSION_CHECK(6, 9, 2)
            QWindowSystemInterfacePrivate::GeometryChangeEvent gce(w,
                QHighDpi::fromNativeWindowGeometry(nativeGeometry, w),
                QHighDpi::fromNativePixels(nativeGeometry, w)
        #else
                QWindowSystemInterfacePrivate::GeometryChangeEvent gce(w,
                QHighDpi::fromNativePixels(nativeGeometry, w)
        #endif
        #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
                , QRect()
        #endif
            );
        }
    }
}

改进后的代码:

  1. 增加了对ww->handle()的空指针检查
  2. w->handle()->geometry()的结果存储在变量nativeGeometry中,避免重复调用
  3. 统一了代码格式,提高了可读性
  4. 简化了条件编译的结构,使代码更清晰
  5. 保持了原有的版本兼容性逻辑

这些改进可以提高代码的安全性、性能和可维护性,同时保持了原有的功能不变。

BLumia added a commit to BLumia/qt5platform-plugins that referenced this pull request Aug 28, 2025
BLumia added a commit to BLumia/qt5platform-plugins that referenced this pull request Aug 28, 2025
@deepin-ci-robot
Copy link
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

BLumia added a commit to linuxdeepin/qt5platform-plugins that referenced this pull request Aug 29, 2025
@BLumia BLumia merged commit 201f8f2 into linuxdeepin:master Aug 29, 2025
21 of 22 checks passed
@BLumia BLumia deleted the ftbfs-qt692 branch August 29, 2025 10:15
BLumia pushed a commit to linuxdeepin/qt6integration that referenced this pull request Aug 29, 2025
Synchronize source files from linuxdeepin/qt5integration.

Source-pull-request: linuxdeepin/qt5integration#280
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