我想知道每当使用 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/