Session ManagementDefinitionsA session is a group of applications running, each of which has a particular state. The session is controlled by a service called the session manager. The applications participating in the session are called session clients. The session manager issues commands to its clients on behalf of the user. These commands may cause clients to commit unsaved changes (for example by saving open files), to preserve their state for future sessions or to terminate gracefully. The set of these operations is called session management. In the common case, a session consists of all applications that a user runs on his desktop at a time. Under Unix/X11, however, a session may as well run on different computers, span multiple displays or just consists of a few applications.
Shutting a session downA session is shut down by the session manager, usually on behalf of the user when she wants to log out. A system might, however, also perform an automatic shutdown in an emergency case, when for example the power is about to be lost. Clearly there is one big difference between both shutdowns. During the first, the user may want to interact with the application, telling exactly which files should be saved and which should be discarded. In the latter case, there's no time for interaction. There may not even be a user sitting in front of the machine!
Protocols and support on different platformsOn MS-Windows, there is nothing like complete session management for applications yet, i.e. no restoring of previous sessions. Windows does, however, support graceful logouts where applications have the chance to cancel the process after getting confirmation from the user. This is the functionality that corresponds to the QApplication::commitData() method. X11 on the other hand supports complete session management since X11R6. Within the life-time of Qt-2.0, virtually all popular Unix/X11 desktops will very likely support the XConsortium standard.
Getting session management to work with QtIn any case you should reimplement QApplication::commitData() to enable your application to take part in the graceful logout process. If you target the MS-Windows platform only, this is all you can and have to provide. Ideally, your application should provide a shutdown dialog similar to the following one:
![]() Example code to this dialog can be found in the documentation of QSessionManager::allowsInteraction(). For complete session management yet only supported on X11R6, you also have to take care of saving the state of the application and potentially restore the state in the next life cycle of the session. This saving is done by reimplementing QApplication::saveState(). All state data you are saving in this function, shall be marked with the session identifier QApplication::sessionId(). This application specific identifier is globally unique, so no clashes will happen.
Restauration is usually done in the application's main()
function. Check if QApplication::isSessionRestored() is Important: In order to allow the window manager to restore window attributes such as stacking order or geometry information, you have to identify your toplevel widgets with an application-wide unique object name (see QObject::setName() ). When restoring the application, you'll have to ensure that all restored toplevel widgets end up with their prior object name again.
Testing and debugging session managementAs mentioned earlier, session management support on Windows is fairly limited due to the lack of this functionality in the Windows operating system itself. Simply shut the session down and verify that your application behaves as wanted. It may be a good idea to launch another application, usually the integrated development environment, before starting your application. This other application will get the shutdown message afterwards, thus permitting you to cancel the shutdown. Otherwise you would have to log in again after each test run, which is not a problem per se but time consuming.
On Unix you can either use a desktop environment that supports
standard X11R6 session management or, the recommended method, use the
session manager reference implementation provided by the X Consortium.
This sample manager is dubbed
|
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
![]()
![]() Le Qt Quarterly au hasard![]() Implémenter un mutex en lecture et en écritureQt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 2.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com