PDA

View Full Version : Can QSessionManager be used for crash problems ?



sujan.dasmahapatra
26th November 2010, 10:04
Dear friends

Can QSessionManager be used for crash problems ? Means if anything happend to the application if it crashed or power interrupted , can we use QSessionManager to save the last session and next time when it starts it should start from there. I appreciate for any on this . Thanks sujan

wysota
26th November 2010, 10:24
I don't think so. You would have to restart the application with a session id manually and to do that you would have to first find the session id which can be troublesome. It will be much easier to take a snapshot of your application state now and then and save it in QSettings.

dawdam
25th November 2015, 17:17
OK, but how save the last snapshot of my app before any crash ? I at the moment I am using the qApp signal aboutToQuit().
How find the way to save the stuff in QSettings when we kill the process ?

I am trying to use QSessionManager and commitDataRequest() signal, but it does not work for me.

Any ideas ?

yeye_olive
25th November 2015, 17:56
aboutToQuit() is for graceful termination. You are interested in crashes.

AFAIK there is no Qt abstraction that gives you a chance to execute arbitrary code when the program is about to crash. A crash occurs when the program performs an illegal operation, such as an invalid memory access. Your OS probably offers a way to install a handler to react to such an event. For instance, Unix sends signals such as SIGSEGV. However, at that point your program is so corrupted that I would not rely too much on high-level abstractions like QSettings if I were you.

If you worry about crashes, why don't you act before it is too late and save the application's state with QSettings from time to time, for instance using a QTimer? Many programs like text editors do just that.

dawdam
4th December 2015, 11:55
OK, thanx, QTimer I think is the best option to do it.