Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C++ Qt how to properly delete widget

If I created any widget something like QPushButton* btn= new QPushButton("Text",this); then does parent widget completely destroys all children widgets or just removes them from it`s internal list?

Should I just use delete btn; or I need to use btn->deleteLater(); to completely destroy it? What the difference between this fundtions?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

does parent widget completely destroys all children widgets or just removes them from it`s internal list?

The parent widget will destroy all children widgets. From the
QWidget::QWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()) documentation:

QWidget -> QAbstractButton -> QPushButton

If parent is nullptr, the new widget becomes a window. If parent is another widget, this widget becomes a child window inside parent. The new widget is deleted when its parent is deleted.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading