fix: remove redundant setParent call in NetItemPrivate#527
Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom Mar 24, 2026
Merged
fix: remove redundant setParent call in NetItemPrivate#52718202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743 merged 1 commit intolinuxdeepin:masterfrom
Conversation
The code was calling setParent on the newly created NetItem object with its private implementation as the parent. This is unnecessary and likely incorrect since the private implementation is not a QObject. The parent- child relationship in Qt should be between QObjects, and NetItemPrivate is not a QObject subclass. This was causing compilation errors due to type mismatch in the setParent call. The fix removes the redundant setParent call which was attempting to set a non-QObject as parent. The NetItem object should manage its own parent relationships separately if needed, not through its private implementation class. Influence: 1. Verify that NetItem objects are still properly created and initialized 2. Test that parent-child relationships work correctly when NetItem objects need them 3. Ensure no memory leaks occur due to missing parent relationships 4. Test that all NetItem subclasses (NetType, etc.) compile and work correctly fix: 移除NetItemPrivate中冗余的setParent调用 代码在新建NetItem对象时尝试将其父对象设置为私有实现类,这是不必要且错误 的,因为私有实现类不是QObject。Qt中的父子关系应该存在于QObject之间,而 NetItemPrivate不是QObject的子类。这导致了setParent调用中的类型不匹配编译 错误。 修复移除了冗余的setParent调用,该调用试图将非QObject对象设置为父对象。 NetItem对象如果需要父子关系,应该单独管理,而不是通过其私有实现类。 Influence: 1. 验证NetItem对象仍能正确创建和初始化 2. 测试当NetItem对象需要父子关系时,这些关系能正常工作 3. 确保不会因缺少父子关系而导致内存泄漏 4. 测试所有NetItem子类(NetType等)都能正确编译和工作
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRemoves an invalid QObject parent assignment in NetItemPrivate by deleting a redundant setParent call when constructing NetItem-derived instances, fixing a compilation error and relying on other mechanisms for object lifetime and relationships. Sequence diagram for NetItem creation without redundant setParentsequenceDiagram
actor Caller
participant NetItemPrivateFactory as NetItemPrivate_New
participant NetItemPrivate
participant NetItem
Caller->>NetItemPrivateFactory: New(type, id)
NetItemPrivateFactory->>NetItemPrivateFactory: switch on type
NetItemPrivateFactory->>NetItemPrivate: create NetTypePrivate instance
NetItemPrivateFactory->>NetItem: create NetType(netItemPrivate, id)
Note over NetItem: QObject parent is provided via constructor
NetItemPrivateFactory->>Caller: return NetItemPrivate instance
Class diagram for NetItemPrivate and NetItem relationship after fixclassDiagram
class NetItemPrivate {
NetItem m_item
+~NetItemPrivate()
+static NetItemPrivate* New(NetType_NetItemType type, QString id)
}
class NetItem {
+NetItem(QObject parent, QString id)
+~NetItem()
}
NetItemPrivate o-- NetItem : m_item
class NetType_NetItemType {
}
NetItemPrivate .. NetType_NetItemType : uses in New()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
caixr23
approved these changes
Mar 24, 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.
The code was calling setParent on the newly created NetItem object with
its private implementation as the parent. This is unnecessary and likely
incorrect since the private implementation is not a QObject. The parent-
child relationship in Qt should be between QObjects, and NetItemPrivate
is not a QObject subclass. This was causing compilation errors due to
type mismatch in the setParent call.
The fix removes the redundant setParent call which was attempting to
set a non-QObject as parent. The NetItem object should manage its own
parent relationships separately if needed, not through its private
implementation class.
Influence:
initialized
objects need them
correctly
fix: 移除NetItemPrivate中冗余的setParent调用
代码在新建NetItem对象时尝试将其父对象设置为私有实现类,这是不必要且错误
的,因为私有实现类不是QObject。Qt中的父子关系应该存在于QObject之间,而
NetItemPrivate不是QObject的子类。这导致了setParent调用中的类型不匹配编译
错误。
修复移除了冗余的setParent调用,该调用试图将非QObject对象设置为父对象。
NetItem对象如果需要父子关系,应该单独管理,而不是通过其私有实现类。
Influence:
Summary by Sourcery
Bug Fixes: