You'll have to check the Windows documentation, it looks like the program simply gets killed.
Cheers,
_
You'll have to check the Windows documentation, it looks like the program simply gets killed.
Cheers,
_
Right, that's what I do, but still - shouldn't it be a cross-platform Qt-solution that addresses the proper handling of such case? I'll try to post the question in qt forum.
Your question has nothing to do with Qt and is operating system specific (for signal handling).
Edit: Here are the signals I trap on Mac OSX which works great: SIGHUP, SIGINT, SIGQUIT, SIGABRT, and SIGTERM. My guess is your app isn't receiving the aboutToQuit signal because a QCoreApplication::quit() has not been done.
Last edited by jefftee; 23rd October 2016 at 19:27.
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
jefftee:
I disagree, it has everything to do with Qt being a cross-platform framework. Trapping the signals was not my first choice, I thought that "aboutToQuit" signal will be fired, and it is not, at least in the code sample that I published. Then I moved to signals.
I am happy to simplify my question: forget signals. Why in this case, when I am closing the console window by clicking on "x", the aboutToQuit signal is not fired? Does the sample that I published work on Mac?
It is, but it is not changing how operating systems work.
It is just part of processes on these operating systems.
Are you sure it is not fired when the application quits?
Have you called QCoreApplication::quit() and the signal did not get emitted?
Apparently the process is killed, no?
How would the process execute code when that happens?
Cheers,
_
You do realize that Qt doesn't abstract *everything* on all OS's, right? Signal handling is one of those things that Qt does not provide any coverage for.
The simple answer to your question is that the aboutToQuit signal is never received because your program has never done a QCoreApplication::quit. Being killed by the OS is not the same as the application shutting down. If you want to have your app cleanup when being killed by closing the window, you'll have to handle the correct signal, which my guess is SIGKILL.
You mention that you *think* SIGKILL is the same as SIGTERM, but it would be easy enough for you to try SIGKILL to see for certain.
Edit: A quick google shows that the signal you are looking for is SIGBREAK. Give that a try.
Last edited by jefftee; 23rd October 2016 at 22:43.
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
TorAn (24th October 2016)
jefftee:
First of all, thank you very much for the help! Yes, SIGBREAK worked.
Now, to the points that you mentioned:
SIGKILL is not available on windows, at least I did not find it in signal.h, that's why I mention the possibility that SIGTERM might be the same thing.
But more importantly no, I absolutely did not realize that Qt does not handle the "abnormal" termination. I tried to use "aboutToQuit" because, as documentation states:
I thought that it applies to the termination of the console window.This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session. The signal is particularly useful if your application has to do some last-second cleanup.
Glad you got it working. My interpretation of the aboutToClose documentation is for a normal (clean) shutdown of your app. i.e. your app calls QCoreApplication::quit() or when the OS informs your app that it's shutting down (or logging off, etc). Those would be considered orderly shutdowns of your console app, but clicking the X on the console window, terminating through the task manager, or kill command all would not result in your app going through normal shutdown, etc.
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
Bookmarks