Skip to content

Commit d5e89e0

Browse files
committed
fix: set parent for NetItem to prevent JS release
1. Added setParent() calls for root and delete items in NetManagerPrivate constructor 2. Added setParent() call when adding child items in NetItemPrivate::addChild() 3. These changes ensure proper parent-child relationships are established 4. Prevents potential issues where JavaScript could release NetItem objects prematurely Influence: 1. Test network item hierarchy remains stable during operations 2. Verify parent-child relationships are correctly maintained 3. Test JavaScript interactions with network items 4. Ensure no memory leaks or premature object destruction 5. Verify network view operations work correctly after these changes fix: 为NetItem设置父对象防止JS释放 1. 在NetManagerPrivate构造函数中为根项目和删除项目添加setParent()调用 2. 在NetItemPrivate::addChild()中添加子项目时调用setParent() 3. 这些更改确保建立正确的父子关系 4. 防止JavaScript可能提前释放NetItem对象的问题 Influence: 1. 测试网络项目层次结构在操作期间保持稳定 2. 验证父子关系是否正确维护 3. 测试JavaScript与网络项目的交互 4. 确保没有内存泄漏或对象过早销毁 5. 验证网络视图操作在这些更改后正常工作
1 parent 3af62ca commit d5e89e0

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

net-view/operation/netmanager.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -207,6 +207,8 @@ NetManagerPrivate::NetManagerPrivate(NetManager *manager)
207207
, m_supportWireless(false)
208208
, q_ptr(manager)
209209
{
210+
m_root->item()->setParent(this);
211+
m_deleteItem->item()->setParent(this);
210212
m_root->updateenabled(false);
211213
addItem(m_root, nullptr);
212214
addItem(m_deleteItem, nullptr);

net-view/operation/private/netitemprivate.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -49,6 +49,7 @@ NetItemPrivate::~NetItemPrivate()
4949
case NetType::Type: \
5050
netItemPrivate = new Net##Type##Private(); \
5151
netItemPrivate->m_item = new Net##Type(netItemPrivate, id); \
52+
netItemPrivate->m_item->setParent(netItemPrivate); \
5253
break
5354

5455
NetItemPrivate *NetItemPrivate::New(NetType::NetItemType type, const QString &id)
@@ -121,6 +122,7 @@ bool NetItemPrivate::addChild(NetItemPrivate *child, int index)
121122

122123
Q_EMIT m_item->childAboutToBeAdded(m_item, index);
123124
m_children.insert(m_children.begin() + index, child->item());
125+
child->m_item->setParent(m_item);
124126

125127
child->m_parent = m_item;
126128
Q_EMIT m_item->childAdded(child->item());
@@ -137,6 +139,7 @@ bool NetItemPrivate::removeChild(NetItemPrivate *child)
137139
Q_EMIT m_item->childAboutToBeRemoved(m_item, it - m_children.begin());
138140
m_children.erase(it);
139141
child->m_parent = nullptr;
142+
child->item()->setParent(nullptr);
140143
Q_EMIT m_item->childRemoved(child->item());
141144
Q_EMIT m_item->childrenChanged();
142145
return true;

0 commit comments

Comments
 (0)