From caff93915af97ae7de75f778a17ae17426a4059a Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Tue, 24 Mar 2026 15:47:41 +0800 Subject: [PATCH] fix: remove redundant setParent call in NetItemPrivate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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等)都能正确编译和工作 --- net-view/operation/private/netitemprivate.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/net-view/operation/private/netitemprivate.cpp b/net-view/operation/private/netitemprivate.cpp index aa0a8ce4..009106b1 100644 --- a/net-view/operation/private/netitemprivate.cpp +++ b/net-view/operation/private/netitemprivate.cpp @@ -49,7 +49,6 @@ NetItemPrivate::~NetItemPrivate() case NetType::Type: \ netItemPrivate = new Net##Type##Private(); \ netItemPrivate->m_item = new Net##Type(netItemPrivate, id); \ - netItemPrivate->m_item->setParent(netItemPrivate); \ break NetItemPrivate *NetItemPrivate::New(NetType::NetItemType type, const QString &id)