I want to run my destructor before click the close button of Qt console application.I found this on stackoverflow,Destructor not called in Qt console scenario .
I have tried to get the return value ,and return the value after.but it is nothing to help.
class MyClass
{
Q_OBJECT
public:
MyClass()
{
qDebug() << "MyClass()";
}
~MyClass()
{
qDebug() << "~MyClass()";
}
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyClass my;
int ret = a.exec();
qDebug() << "this line will not run.";
return ret;
}
I want to know why it doesn't run my destructor.
If I want to run it.how?
I want it to output MyClass()
and this line will not run.
and ~MyClass()
when I click the close button.