qt 4.7 removeChild() 和内存
我正在编写一个 C++ qt 应用程序。在一部分中,我正在创建一个 QTreeWidget。用户可以在该树中创建和删除条目。 因此,当用户创建一个项目时,他将调用一个函数,然后该函数本身会调用:
QTreeWidgetItem* newItem = new QTreeWidgetItem();
当用户稍后决定删除该条目时,他会调用一个函数,然后该函数本身会调用:
QTreeWidgetItem* curItem = _ui->qTreeWidget->currentItem();
QTreeWidgetItem* parent = curItem->parent();
parent->removeChild(curItem);
现在对我来说擦除的问题是:内存怎么样该物品被占用? Qt 4.7 文档对removeChild的说法如下:
void QTreeWidgetItem::removeChild (QTreeWidgetItem * child) 删除子项指定的给定项目。删除的项目不会被删除。
那么如何删除孩子呢?
预先非常感谢! 唐尼
Im writing a c++ qt application. In one part I'm creating a QTreeWidget. The user has all possibilities to create and delete entries in that tree.
So when the user creates a item he will call a function which then itself calls:
QTreeWidgetItem* newItem = new QTreeWidgetItem();
When the user later decides to delete the entry, he calls a function which then itself will call:
QTreeWidgetItem* curItem = _ui->qTreeWidget->currentItem();
QTreeWidgetItem* parent = curItem->parent();
parent->removeChild(curItem);
The question that erases for me is now: what about the memory this item occupied? What The Qt 4.7 doc says to removeChild is the following:
void QTreeWidgetItem::removeChild ( QTreeWidgetItem * child )
Removes the given item indicated by child. The removed item will not be deleted.
So how do i delete a child?
Thanks a lot in advance!
Donny
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样
?
根据 文档,析构函数将删除该项目从包含它的树中删除,所以我认为您甚至不需要事先执行
removeChild
。How about
?
According to the documentation, the destructor will remove the item from the tree in which it is included, so I think you don't even need to perform the
removeChild
beforehand.通常,您只需在正确的时间删除对象:
删除只是从父对象中删除其链接。
或者安排稍后删除:
You would normally just delete your object at the right time with:
The remove is just removing its link from the parent.
or perhaps schedule it for deletion later: