Skip to content

fix: remove redundant setParent call in NetItemPrivate#527

Merged
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:master
Mar 24, 2026
Merged

fix: remove redundant setParent call in NetItemPrivate#527
18202781743 merged 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Mar 24, 2026

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等)都能正确编译和工作

Summary by Sourcery

Bug Fixes:

  • Fix a compilation error by dropping a redundant setParent call that attempted to use a non-QObject NetItemPrivate instance as the parent of a NetItem.

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等)都能正确编译和工作
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Removes 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 setParent

sequenceDiagram
    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
Loading

Class diagram for NetItemPrivate and NetItem relationship after fix

classDiagram
    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()
Loading

File-Level Changes

Change Details Files
Fix invalid QObject parenting by removing the redundant setParent call when creating NetItem instances in the NetItemPrivate factory macro.
  • In the NetItemPrivate factory macro, stop calling setParent with NetItemPrivate as the parent of the newly created NetType instance.
  • Rely on existing ownership/lifetime management for NetItem and NetItemPrivate instead of a QObject parent-child relationship between them.
net-view/operation/private/netitemprivate.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[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.

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

@18202781743 18202781743 merged commit 513ba95 into linuxdeepin:master Mar 24, 2026
17 of 19 checks passed
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