Skip to content

Commit 73535d4

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 73535d4

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

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: 2 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

@@ -121,6 +121,7 @@ bool NetItemPrivate::addChild(NetItemPrivate *child, int index)
121121

122122
Q_EMIT m_item->childAboutToBeAdded(m_item, index);
123123
m_children.insert(m_children.begin() + index, child->item());
124+
child->m_item->setParent(m_item);
124125

125126
child->m_parent = m_item;
126127
Q_EMIT m_item->childAdded(child->item());

0 commit comments

Comments
 (0)