0


Could you tell me how can I determine between QMainWindow close event initiated by user and abonormal termination by SIG_KILL in Linux or TerminateProcess() in Windows?
That's because the difference in urgency exists.
I can refuse closing by user or user can think as long as required.
But I have to save intermediate results and current state as soon as possible when aborting or till the user will do next fatal abort try.
I can try to figure out analysing the mouse position on closeEvent(). But it depends on the taskbar look. I can set the app to non-minimized state and wait the next user actions. But that's not a good behaviour in the abort case. User can try the next fatal abort actions or the time for save would lost.
Best regards, Gennady

Mat
  • 202,337
  • 40
  • 393
  • 406

1 Answers1

2

If you application receives a SIGKILL, it will not have any time to do anything. It is terminated on the spot. You can't catch or block that signal. So you can't "differentiate" a SIGKILL from normal application shutdown: you will not know when you have been forcefully killed. (Same thing for TerminateProcess().)

If you need to do something during normal application shutdown, you should connect your cleanup routine to the QCoreApplication::aboutToQuit() signal. Check the docs, that is exactly what it is designed for.

Mat
  • 202,337
  • 40
  • 393
  • 406