Create a QT console program, use a class object such as TestClass TC, then run, then close the console, why the TestClass destructor is not executed.
int main (int argc, char *argv[])
{
qcoreapplication A (argc, argv);
TestClass TC;
return a.exec ();
}
However, if qcoreapplication is not applicable, and return 1 directly, the destructor can be executed. Why does the QT console program not call the destructor? Does it have a problem with memory management?
Of course not, it is in the wrong way, a.exec () will enter the QT EventLoop, equivalent to an infinite loop. When the console is closed, it is tantamount to forcing the program to exit without executing the program in sequence. So, I understand that the right way to use it is to call the exit quit, close, or exit methods when you want to quit. Like what
<pre name= "code" class= "CPP" >int main (int argc, char *argv[])
{
qcoreapplication A (argc, argv);
TestClass TC;
Qtimer T;
T.connect (&t, SIGNAL (timeout ()), &a, SLOT (Quit ()));
T.start (+);
return a.exec ();
}