Do we need a virtual destructor for a classes which are gonna be used in Qt-way: set QObject
-parent which will call in QObject's destructor deleteLater()
or something like that for any object for which it was set as parent?
For example:
class MyWidget : public QWidget {
public:
MyWidget() {
w = new QWidget(this);
// "w" will be deleted automatically by parent MyWidget::QWidget::QObject's destructor afaik
}
private:
QWidget *w;
}
Do we need a virtual destructor for MyWidget
class if it is gonna be inherited? I see no reason for this because it does not delete anything and each property of the class which is derived from QObject
will be deleted from MyWidget::QWidget::QObject's destructor.
It doesn't matter if you add it or not as QObject
inherited by QWidget
has a virtual destructor, and this is propagated through the whole hierarchy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With