c++ - 如果使用 'this' 创建(新建)Qt 对象需要删除还是自动删除?

标签 c++ qt memory-leaks

我想知道每当使用 this 关键字或任何其他 Qt 对象在堆中创建任何 Qt 对象(例如 QTimer)时,需要被删除还是被父级自动删除?

最佳答案

如果您的对象是对象树的父对象,则当树根对象被销毁时,它将被收集。如果需要,您仍然可以在此之前删除它。

QObjects organize themselves in object trees. When you create a QObject with another object as parent, the object will automatically add itself to the parent's children() list. The parent takes ownership of the object; i.e., it will automatically delete its children in its destructor.

关于c++ - 如果使用 'this' 创建(新建)Qt 对象需要删除还是自动删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46865250/

相关文章:

c++ - 如何在 Visual Studio 2008 中使用 .a lib 文件?

C++ 类和 emacs 编辑器

c++ - 在 C++20 中迭代结构的成员

windows - native 内存泄漏 - 如何找到分配源的调用堆栈

c++ - 在 C++ 中使用比子构造函数更多的参数调用父构造函数

c++ - 从 QHash 中删除元素范围

linux - 如何将系统输出重定向到我的 gui 应用程序(qt、linux)?

c++ - 如何在 Qt 中为 qmake 指定一个库文件依赖?

c - 内存泄漏,realloc() 函数

ios - 在子类中使用 GKStateMachine 的泄漏