Execute destructors when pressing "stop"
-
In my application I catch the
SIGTERM
signal:#include <QCoreApplication> #include <QObject> #include "engine.h" #include "signalshandler.h" static int setup_unix_signal_handlers() { struct sigaction term; term.sa_handler = SignalsHandler::termSignalHandler; sigemptyset(&term.sa_mask); term.sa_flags = 0; term.sa_flags |= SA_RESTART; if (sigaction(SIGTERM, &term, 0)) return 1; return 0; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); SignalsHandler handler; setup_unix_signal_handlers(); QObject::connect(&handler, &SignalsHandler::quit, &a, QCoreApplication::quit); //... return a.exec(); }
It works fine, i.e. if I try to kill my application from command line the destructors all executed and the application shuts down nicely.
I want to achieve the same behavior when I press "stop" after launching the program from QtCreator.
Here the behavior is not consistent. It seems that "some" destructors are executed, but not all of them. After a while the application "crashes":10:07:01: User requested stop. Shutting down...
10:07:01: Remote process crashed.I placed breakpoints (or
qDebug()
calls) inside the destructors but as I said, not all of them are executed and they change from run to run.My wild guess is QtCreator after a while force the process to stop without waiting for the exit.
Is there a way to do a correct shutdown of the application inside QtCreator?
-
In my application I catch the
SIGTERM
signal:#include <QCoreApplication> #include <QObject> #include "engine.h" #include "signalshandler.h" static int setup_unix_signal_handlers() { struct sigaction term; term.sa_handler = SignalsHandler::termSignalHandler; sigemptyset(&term.sa_mask); term.sa_flags = 0; term.sa_flags |= SA_RESTART; if (sigaction(SIGTERM, &term, 0)) return 1; return 0; } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); SignalsHandler handler; setup_unix_signal_handlers(); QObject::connect(&handler, &SignalsHandler::quit, &a, QCoreApplication::quit); //... return a.exec(); }
It works fine, i.e. if I try to kill my application from command line the destructors all executed and the application shuts down nicely.
I want to achieve the same behavior when I press "stop" after launching the program from QtCreator.
Here the behavior is not consistent. It seems that "some" destructors are executed, but not all of them. After a while the application "crashes":10:07:01: User requested stop. Shutting down...
10:07:01: Remote process crashed.I placed breakpoints (or
qDebug()
calls) inside the destructors but as I said, not all of them are executed and they change from run to run.My wild guess is QtCreator after a while force the process to stop without waiting for the exit.
Is there a way to do a correct shutdown of the application inside QtCreator?
@Mark81 said in Execute destructors when pressing "stop":
I press "stop"
What is "stop"?
What exactly do you do when "stop" is pressed? -
@Mark81 said in Execute destructors when pressing "stop":
I press "stop"
What is "stop"?
What exactly do you do when "stop" is pressed?@jsulm This is the "stop" button, as the tooltip says:
What exactly do you do when "stop" is pressed?
I do nothing :-)
I'm expecting QtCreator sends asigterm
signal to my application. Because I'm catching it, and it's tied to thequit
slot, I'm expecting the destructors are called.And it almost works, but (I guess) there is no time to execute all the destructor and my process crashes before completing the shutdown.
-
This button stops the application immediately. It's no button to properly shut down an application so no dtors are run.
-
This button stops the application immediately. It's no button to properly shut down an application so no dtors are run.
@Christian-Ehrlicher ok, is there a way to add a customized button in QtCreator? Or a way to send a char to stdin? I'm working on a headless remote device.
-
You can send a sigquit command to your app and react on this. You can send this signal with 'kill'.
-
You can send a sigquit command to your app and react on this. You can send this signal with 'kill'.
@Christian-Ehrlicher of course! This is what I'm doing right now:
It works fine, i.e. if I try to kill my application from command line the destructors all executed and the application shuts down nicely.
I was just looking for a convenient way within QtCreator.
It seems they didn't think about this feature.