Qt's parent–child mechanism is implemented in QObject. When we create an object (a widget,validator, or any other kind) with a parent, the parent adds the object to the list of its children.When the parent is deleted, it walks through its list of children and deletes each child. Thechildren themselves then delete all of their children, and so on recursively until none remain.The parent–child mechanism greatly simplifies memory management, reducing the risk ofmemory leaks. The only objects we must call delete on are the objects we create with new and that have no parent. And if we delete a child object before its parent, Qt will automatically remove that object from the parent's list of children.
Qt's parent–child mechanism
最新推荐文章于 2024-12-23 22:57:10 发布