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
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.
Related
If I don't provide an activity to manage the lifecycle, and instead do it manually but never close the adapter by calling stopListening(), what happens?
In that case the listener will remain active until the app is closed, or the socket is killed by the operating system. You'll be wasting your user's bandwidth and battery life, downloading data that they never see.
I have an application for which a cleanup code should be run regardless of the way how the process ended. For example, if the program is being closed by the OS due to a restart, the cleanup code should be executed. Or if CTRL+C is pressed, the cleanup code should be executed.
I've found the QCoreApplication::aboutToQuit signal.
The docs for the signal state:
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. Note that no user interaction is possible in this
state.
However after testing, I've noticed that the signal isn't emitted when CTRL-C is pressed. It also isn't emitted when terminated by kill.
On what 'exit' events is the signal emitted?
My current opinion is that QCoreApplication::aboutToQuit is useless for handling outside signals and that it is used for 'exiting from inside an app' kind of events (a user clicks the X button to close the window), but won't help you if you want to make sure a certain event is executed even on a segmentation fault or the process being externally killed.
You can do it like this (had the same problem a while back and found it to work quite well):
http://www.thegeekstuff.com/2012/03/catch-signals-sample-c-code/
Good sample code + all system signals:
http://www.yolinux.com/TUTORIALS/C++Signals.html
Is it possible to detect in Flex application browser window close event so that an action can be
started when user closes Flex application, does anyone know how to do that if it's possible in the
first place? The reason why i am asking this is because i have a multiuser Flex application where
every user has it's own directory on a server side. Application has logout button which triggers
cleanup of user's directory but what if the user just closes the window? I would like to be able
to lunch that same cleanup upon browser close window
In the page hosting your app, write a Javascript function triggered by window.onbeforeunload, and this function can call a function inside your Flex application.
Note that the onbeforeunload function is not guaranteed to work for all browsers.
I would not recommend that approach because the closing action fails too often, meaning worthless. My browser freezes and force-quitted several times a day. My computer sometimes freezes. My internet connection sometimes dies. I think, some browsers even do not guarantee those kinds of actions executed every time.
So, the session timeout might be one safe way in most cases.
You can also try having a socket connection, so that your server can ping if a user is alive and also can detect if socket is closed. Even socket, however, can be unresponsive or can be disconnected sometimes while user is still using the application.
You might want to be strategic.
Is there a way to detect when a windows process is waiting for user input.
For instance, when you click on a particular program it loads, in this case the program's process is probably in loading state rite?
what happens when the program is fully loaded and is waiting for user input to procedure to next step. Is there a way to detect this?
Cheers
Call WaitForInputIdle with a handle to a process. it will suspend execution until the program completes its initialization and is waiting for user input with no input pending.
Is that possible to achieve using Adobe Air or any other suggestion? I have an app which record user time and to prevent user don't forget i think similar solution will work.
Thanks!
You can bind a listener to close event for the application. When OS received shut down command, it'll try to terminate processes so your app will trigger close event. I haven't tested but hopefully this will work. At that moment, you can register user's session data. That's what other software do when you want to turn off, a little delay...