fix(ctextedit): fix crash and Qt6 deprecated API usage#195
Merged
wyu71 merged 1 commit intolinuxdeepin:develop/snipefrom Mar 12, 2026
Merged
fix(ctextedit): fix crash and Qt6 deprecated API usage#195wyu71 merged 1 commit intolinuxdeepin:develop/snipefrom
wyu71 merged 1 commit intolinuxdeepin:develop/snipefrom
Conversation
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider extracting the Qt 5/6 font family handling into a small helper (e.g.,
getCurrentFontFamily()/setFormatFontFamily()static functions) to avoid scattering version-specific#iflogic across multiple methods. - In
updateSelectionFormat(), resetting_selectionFmtto a defaultQTextCharFormaton emptyfmtsmay change existing behavior; if the intention is just to avoid a crash, you might instead early-return without altering_selectionFmtto preserve the previous selection state. - The qDebug() logging in
setCurrentFontFamily()could become noisy in normal usage; consider guarding it behind a debug flag or removing it if it's no longer needed for diagnosing this bug.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the Qt 5/6 font family handling into a small helper (e.g., `getCurrentFontFamily()` / `setFormatFontFamily()` static functions) to avoid scattering version-specific `#if` logic across multiple methods.
- In `updateSelectionFormat()`, resetting `_selectionFmt` to a default `QTextCharFormat` on empty `fmts` may change existing behavior; if the intention is just to avoid a crash, you might instead early-return without altering `_selectionFmt` to preserve the previous selection state.
- The qDebug() logging in `setCurrentFontFamily()` could become noisy in normal usage; consider guarding it behind a debug flag or removing it if it's no longer needed for diagnosing this bug.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
eb11921 to
4df3972
Compare
Add empty check before calling first() on fmts to prevent crash. Use fontFamilies()/setFontFamilies() for Qt 6.1+ compatibility. 添加空检查防止fmts为空时崩溃,Qt 6.1+使用新API替代废弃接口。 Log: 修复文本编辑器崩溃问题及Qt6兼容性 PMS: BUG-352807 Influence: 修复选中空区域时可能崩溃的问题,解决Qt 6.1+编译时的废弃API警告。
deepin pr auto review这段代码主要是为了适配 Qt 6.1.0 及以上版本中关于字体处理 API 的变更,同时修复了一个潜在的空指针/空列表访问崩溃问题。以下是对这段代码的详细审查意见: 1. 语法与逻辑审查
2. 代码质量审查
3. 代码性能审查
4. 代码安全审查
5. 改进建议尽管代码整体质量很高,但仍有以下微小的优化或建议空间:
总结这段代码修改是高质量的。它成功地处理了 Qt 版本升级带来的 API 变更,并修复了一个可能导致崩溃的严重 Bug。修改后的代码在逻辑上更加严密,性能上也有细微优化。除了上述几点锦上添花的建议外,该代码可以直接合并。 |
lzwind
approved these changes
Mar 12, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, wyu71 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add empty check before calling first() on fmts to prevent crash. Use fontFamilies()/setFontFamilies() for Qt 6.1+ compatibility.
添加空检查防止fmts为空时崩溃,Qt 6.1+使用新API替代废弃接口。
Log: 修复文本编辑器崩溃问题及Qt6兼容性
PMS: BUG-352807
Influence: 修复选中空区域时可能崩溃的问题,解决Qt 6.1+编译时的废弃API警告。
Summary by Sourcery
Prevent text editor crashes on empty selection and update font family handling for Qt 6 compatibility.
Bug Fixes:
Enhancements: