fix: defer icon source resolution until component completion#3154
Merged
18202781743 merged 1 commit intolinuxdeepin:dcc-coredumpfrom Apr 3, 2026
Merged
fix: defer icon source resolution until component completion#315418202781743 merged 1 commit intolinuxdeepin:dcc-coredumpfrom
18202781743 merged 1 commit intolinuxdeepin:dcc-coredumpfrom
Conversation
1. Added QQmlParserStatus interface to DccObject to track QML component lifecycle 2. Introduced m_componentComplete flag to track when component construction is finished 3. Modified setIcon() to delay icon source resolution until componentComplete() is called 4. Added updateIconSource() private method to handle icon URL resolution logic 5. Added componentComplete() override to set completion flag and trigger icon source update 6. Added classBegin() override as required by QQmlParserStatus interface 7. Made DccObject inherit from QQmlParserStatus and added Q_INTERFACES macro 8. Added friend declaration for DccModel class to access private members This fix addresses an issue where icon source resolution was attempted during QML component construction phase when the QQmlContext might not be fully initialized. By deferring the URL resolution until componentComplete(), we ensure the context is properly set up, preventing potential crashes or incorrect icon paths. Log: Fixed icon loading issues during control center module initialization Influence: 1. Test icon loading for all control center modules 2. Verify icons appear correctly after QML component initialization 3. Test dynamic icon changes after component completion 4. Verify no crashes during control center startup 5. Test icon resolution with both relative and absolute paths 6. Verify icon updates when setIcon() is called after component completion fix: 延迟图标源解析直到组件完成 1. 为 DccObject 添加 QQmlParserStatus 接口以跟踪 QML 组件生命周期 2. 引入 m_componentComplete 标志来跟踪组件构造何时完成 3. 修改 setIcon() 方法,将图标源解析延迟到 componentComplete() 被调用时 4. 添加 updateIconSource() 私有方法来处理图标 URL 解析逻辑 5. 添加 componentComplete() 重写以设置完成标志并触发图标源更新 6. 添加 classBegin() 重写以满足 QQmlParserStatus 接口要求 7. 使 DccObject 继承自 QQmlParserStatus 并添加 Q_INTERFACES 宏 8. 为 DccModel 类添加友元声明以访问私有成员 此修复解决了在 QML 组件构造阶段尝试解析图标源时 QQmlContext 可能未完全初 始化的问题。通过将 URL 解析延迟到 componentComplete(),我们确保上下文已 正确设置,防止潜在的崩溃或错误的图标路径。 Log: 修复控制中心模块初始化期间的图标加载问题 Influence: 1. 测试所有控制中心模块的图标加载 2. 验证 QML 组件初始化后图标是否正确显示 3. 测试组件完成后的动态图标更改 4. 验证控制中心启动期间无崩溃 5. 测试相对路径和绝对路径的图标解析 6. 验证组件完成后调用 setIcon() 时的图标更新
Reviewer's GuideDefers DccObject icon URL resolution until the QML component lifecycle has completed by implementing QQmlParserStatus, tracking component completion, and centralizing icon source updates in a new helper method. Sequence diagram for deferred icon URL resolution in DccObjectsequenceDiagram
participant QmlEngine
participant QQmlContext
participant DccObject
participant DccObject_Private as DccObject_Private
QmlEngine->>DccObject: construct
QmlEngine->>DccObject: classBegin()
activate DccObject
QmlEngine->>DccObject: setIcon(icon)
DccObject->>DccObject_Private: store icon in m_icon
DccObject->>DccObject: emit iconChanged
DccObject->>DccObject_Private: check m_componentComplete (false)
DccObject-->DccObject: skip updateIconSource()
QmlEngine->>DccObject: componentComplete()
DccObject->>DccObject_Private: m_componentComplete = true
DccObject->>DccObject: updateIconSource()
DccObject->>QQmlContext: qmlContext(this)
QQmlContext-->>DccObject: context
DccObject->>QQmlContext: resolvedUrl(m_icon)
QQmlContext-->>DccObject: resolvedUrl
DccObject->>DccObject_Private: store resolvedUrl in m_iconSource
DccObject->>DccObject: emit iconSourceChanged
deactivate DccObject
QmlEngine->>DccObject: setIcon(newIcon) after completion
DccObject->>DccObject_Private: update m_icon
DccObject->>DccObject: emit iconChanged
DccObject->>DccObject: updateIconSource()
DccObject->>QQmlContext: qmlContext(this)
QQmlContext-->>DccObject: context
DccObject->>QQmlContext: resolvedUrl(m_icon)
QQmlContext-->>DccObject: resolvedUrl
DccObject->>DccObject_Private: update m_iconSource
DccObject->>DccObject: emit iconSourceChanged
Class diagram for updated DccObject lifecycle and icon handlingclassDiagram
class QQmlParserStatus {
<<interface>>
+classBegin() void
+componentComplete() void
}
class DccModel
class DccObject {
<<QObject>>
+setIcon(icon QString) void
+iconSource() QUrl
+classBegin() void
+componentComplete() void
-updateIconSource() void
-p_ptr DccObject_Private*
}
class DccObject_Private {
-m_pageType quint8
-m_weight quint16
-m_flags quint32
-m_componentComplete bool
-m_icon QString
-m_iconSource QUrl
-q_ptr DccObject*
-m_parent DccObject*
-m_currentObject DccObject*
}
DccObject ..|> QQmlParserStatus
DccObject *-- DccObject_Private : holds
DccModel .. DccObject : friend
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/dde-control-center/plugin/dccobject.cpp" line_range="337" />
<code_context>
void DccObject::setIcon(const QString &icon)
</code_context>
<issue_to_address>
**question (bug_risk):** Consider whether delaying iconSource updates until componentComplete is acceptable for C++-only usage.
With the new logic, if setIcon is called before componentComplete, iconSource and iconSourceChanged are deferred. That’s fine for QML, but for objects constructed and used only from C++ (no QQmlEngine / componentComplete), iconSource will never update. If C++‑only usage matters, consider checking `qmlContext(this)` instead of `m_componentComplete`, or treating the "no QQml context" case as implicitly complete so iconSource still gets resolved/propagated.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
caixr23
approved these changes
Apr 3, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, caixr23 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.
This fix addresses an issue where icon source resolution was attempted during QML component construction phase when the QQmlContext might not be fully initialized. By deferring the URL resolution until componentComplete(), we ensure the context is properly set up, preventing potential crashes or incorrect icon paths.
Log: Fixed icon loading issues during control center module initialization
Influence:
fix: 延迟图标源解析直到组件完成
此修复解决了在 QML 组件构造阶段尝试解析图标源时 QQmlContext 可能未完全初
始化的问题。通过将 URL 解析延迟到 componentComplete(),我们确保上下文已
正确设置,防止潜在的崩溃或错误的图标路径。
Log: 修复控制中心模块初始化期间的图标加载问题
Influence:
Summary by Sourcery
Defer QML icon URL resolution in DccObject until the component construction is complete to avoid using an uninitialized QQmlContext.
Bug Fixes:
Enhancements: