The session manager is responsible for session management, most importantly for interruption and resumption. A "session" is a kind of record of the state of the system, e.g. which applications were run at start up and which applications are currently running. The session manager is used to save the session, e.g. when the machine is shut down; and to restore a session, e.g. when the machine is started up. Use QSettings to save and restore an individual application's settings, e.g. window positions, recently used files, etc.
TQSessionManager provides an interface between the application and the session manager so that the program can work well with the session manager. In Qt, session management requests for action are handled by the two virtual functions QApplication::commitData() and QApplication::saveState(). Both provide a reference to a session manager object as argument, to allow the application to communicate with the session manager.
During a session management action (i.e. within commitData() and saveState()), no user interaction is possible \fIunless\fR the application got explicit permission from the session manager. You ask for permission by calling allowsInteraction() or, if it's really urgent, allowsErrorInteraction(). TQt does not enforce this, but the session manager may.
You can try to abort the shutdown process by calling cancel(). The default commitData() function does this if some top-level window rejected its closeEvent().
For sophisticated session managers provided on Unix/X11, TQSessionManager offers further possibilites to fine-tune an application's session management behavior: setRestartCommand(), setDiscardCommand(), setRestartHint(), setProperty(), requestPhase2(). See the respective function descriptions for further details.
\fCTQSessionManager::RestartIfRunning\fR - if the application is still running when the session is shut down, it wants to be restarted at the start of the next session.
\fCTQSessionManager::RestartAnyway\fR - the application wants to be started at the start of the next session, no matter what. (This is useful for utilities that run just after startup and then quit.)
This is similar to allowsInteraction(), but also tells the session manager that an error occurred. Session managers may give error interaction request higher priority, which means that it is more likely that an error interaction is permitted. However, you are still not guaranteed that the session manager will allow interaction.
.PP
See also allowsInteraction(), release(), and cancel().
Asks the session manager for permission to interact with the user. Returns TRUE if interaction is permitted; otherwise returns FALSE.
.PP
The rationale behind this mechanism is to make it possible to synchronize user interaction during a shutdown. Advanced session managers may ask all applications simultaneously to commit their data, resulting in a much faster shutdown.
.PP
When the interaction is completed we strongly recommend releasing the user interaction semaphore with a call to release(). This way, other applications may get the chance to interact with the user while your application is still busy saving data. (The semaphore is implicitly released when the application exits.)
.PP
If the user decides to cancel the shutdown process during the interaction phase, you must tell the session manager that this has happened by calling cancel().
.PP
Here's an example of how an application's QApplication::commitData() might be implemented:
Requests a second session management phase for the application. The application may then return immediately from the QApplication::commitData() or QApplication::saveState() function, and they will be called again once most or all other applications have finished their session management.
.PP
The two phases are useful for applications such as the X11 window manager that need to store information about another application's windows and therefore have to wait until these applications have completed their respective session management tasks.
.PP
Note that if another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.
If the session manager is capable of restoring sessions it will execute \fIcommand\fR in order to restore the application. The command defaults to
.PP
.nf
.br
appname -session id
.br
.fi
.PP
The \fC-session\fR option is mandatory; otherwise QApplication cannot tell whether it has been restored or what the current session identifier is. See QApplication::isSessionRestored() and QApplication::sessionId() for details.
.PP
If your application is very simple, it may be possible to store the entire application state in additional command line options. This is usually a very bad idea because command lines are often limited to a few hundred bytes. Instead, use QSettings, or temporary files or a database for this purpose. By marking the data with the unique sessionId(), you will be able to restore the application in a future session.
.PP
See also restartCommand(), setDiscardCommand(), and setRestartHint().
Sets the application's restart hint to \fIhint\fR. On application startup the hint is set to RestartIfRunning.
.PP
Note that these flags are only hints, a session manager may or may not respect them.
.PP
We recommend setting the restart hint in QApplication::saveState() because most session managers perform a checkpoint shortly after an application's startup.