From 1dba2a808feb934ef4f430c4180cf3f526469223 Mon Sep 17 00:00:00 2001 From: fuleyi Date: Fri, 5 Dec 2025 13:38:14 +0800 Subject: [PATCH] fix: add Qt6 version guard for cursor context handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added conditional compilation guards around cursor context management code that is specific to Qt6. The m_cursorContext member only exists in Qt6 version, so accessing it in Qt5 builds would cause compilation errors. This fix ensures the code only compiles the Qt6-specific cursor context cleanup and reinitialization when building with Qt6 or later. The changes include: 1. Wrapping cursor context freeing and reinitialization with #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 2. Added comment noting that m_cursorContext only exists in Qt6 3. Properly guards against accessing Qt6-specific APIs in Qt5 builds Influence: 1. Verify application compiles successfully with both Qt5 and Qt6 2. Test cursor functionality remains working in both Qt versions 3. Confirm cursor theme changes are properly handled in Qt6 builds 4. Validate no memory leaks in cursor context management for Qt6 fix: 为光标上下文处理添加 Qt6 版本保护 添加了条件编译保护,围绕特定于 Qt6 的光标上下文管理代码。m_cursorContext 成员仅存在于 Qt6 版本中,因此在 Qt5 构建中访问它会导致编译错误。此修复 确保代码仅在 Qt6 或更高版本构建时编译 Qt6 特定的光标上下文清理和重新初 始化。 更改包括: 1. 使用 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 包装光标上下文释放和 重新初始化 2. 添加注释说明 m_cursorContext 仅存在于 Qt6 3. 在 Qt5 构建中正确防止访问 Qt6 特定 API Influence: 1. 验证应用程序在 Qt5 和 Qt6 下都能成功编译 2. 测试光标功能在两个 Qt 版本中保持正常工作 3. 确认在 Qt6 构建中光标主题更改得到正确处理 4. 验证 Qt6 中光标上下文管理没有内存泄漏 --- xcb/dplatformintegration.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xcb/dplatformintegration.cpp b/xcb/dplatformintegration.cpp index 314181c7..0a009c13 100644 --- a/xcb/dplatformintegration.cpp +++ b/xcb/dplatformintegration.cpp @@ -1074,7 +1074,9 @@ static void cursorThemePropertyChanged(xcb_connection_t *connection, const QByte } xcb_cursor->m_cursorHash.clear(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) // source from: QXCBCursor::updateContext() + // Note: m_cursorContext only exists in Qt6 if (xcb_cursor->m_cursorContext) { xcb_cursor_context_free(xcb_cursor->m_cursorContext); } @@ -1084,6 +1086,7 @@ static void cursorThemePropertyChanged(xcb_connection_t *connection, const QByte if (xcb_cursor_context_new(conn, xcb_cursor->m_screen->screen(), &xcb_cursor->m_cursorContext) < 0) { xcb_cursor->m_cursorContext = nullptr; } +#endif } }