Try the following:
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui>
{
Q_OBJECT
public:
~Widget()
{
qDebug() << "I AM IN DESTRUCTOR OF WIDGET!";
}
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0) : QWidget(parent) {}
~Widget()
{
qDebug() << "I AM IN DESTRUCTOR OF WIDGET!";
}
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
#include "widget.h"
int main(int argc, char **argv)
{
Widget *widget = new Widget(&mainWin);
mainWin.show();
return app.exec();
};
#include "widget.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QMainWindow mainWin;
Widget *widget = new Widget(&mainWin);
mainWin.show();
return app.exec();
};
To copy to clipboard, switch view to plain text mode
See that whilst in the mainWindow I've not set up a parent when the app closes it gets deleted (because it's on the stack) and then the widget which is a child of mainWindow is deleted. (Or at least the destructor is called!)
Bookmarks