Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QMainWindow destructor

Why the QMainWindow's destructor is not virtual? If I inherit a class MainWindow from QMainWindow and have some pointer attribute on it I can't delete the memory using MainWindow's destructor.

like image 993
Jarzka Avatar asked Aug 24 '26 08:08

Jarzka


2 Answers

QMainWindow's destructor is an override of an already existing destructor (QWidget::~QWidget()) which in turn is an override of a virtual destructor (virtual QObject::~QObject()). Thus, QMainWindow::~QMainWindow() is virtual. The same rules apply as with normal member functions.

like image 55
Nikos C. Avatar answered Aug 26 '26 01:08

Nikos C.


QObject's destructor has been declared as virtual. QMainWindow is derived from QObject indirectly. I belive QMainWindow's destruct does not need virtual in this case. Did you set breakpoint in QMainWindow's destructor while deleting your derived class?

like image 35
Joonhwan Avatar answered Aug 26 '26 00:08

Joonhwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!