📄 session.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/doc/session.doc:36 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Session Management</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Session Management</h1><p> <h2> Definitions </h2><a name="1"></a><p> A <em>session</em> is a group of applications running, each of which has aparticular state. The session is controlled by a service called the <em>session</em> <em>manager</em>. The applications participating in the session arecalled <em>session</em> <em>clients</em>.<p> The session manager issues commands to its clients on behalf of theuser. These commands may cause clients to commit unsaved changes (forexample by saving open files), to preserve their state for futuresessions or to terminate gracefully. The set of these operations iscalled <em>session</em> <em>management</em>.<p> In the common case, a session consists of all applications that auser runs on their desktop at a time. Under Unix/X11, however, asession may include applications running on different computers andmay span multiple displays.<p> <h2> Shutting a session down </h2><a name="2"></a><p> A session is shut down by the session manager, usually on behalf ofthe user when they want to log out. A system might alsoperform an automatic shutdown in an emergency situation, for example,if power is about to be lost. Clearly there is a significant big differencebetween both shutdowns. During the first, the user may want tointeract with the application, specifying exactly which files should besaved and which should be discarded. In the latter case, there's notime for interaction. There may not even be a user sitting in front ofthe machine!<p> <h2> Protocols and support on different platforms</h2><a name="3"></a><p> On Mac OS X and MS-Windows, there is nothing like complete sessionmanagement for applications yet, i.e. no restoring of previoussessions. They do support graceful logouts where applicationshave the chance to cancel the process after getting confirmation fromthe user. This is the functionality that corresponds to the <a href="qapplication.html#commitData">QApplication::commitData</a>() method.<p> X11 has supported complete session management since X11R6.<p> <h2> Getting session management to work with Qt </h2><a name="4"></a><p> Start by reimplementing <a href="qapplication.html#commitData">QApplication::commitData</a>() toenable your application to take part in the graceful logout process. Ifyou target the MS-Windows platform only, this is all you can and haveto provide. Ideally, your application should provide a shutdown dialogsimilar to the following one:<p> <center><img src="session.png" alt="A typical dialog on shutdown"></center> <p> Example code to this dialog can be found in the documentation of <a href="qsessionmanager.html#allowsInteraction">QSessionManager::allowsInteraction</a>().<p> For complete session management (only supported on X11R6 at present), you alsohave to take care of saving the state of the application andpotentially restore the state in the next life cycle of the session.This saving is done by reimplementing <a href="qapplication.html#saveState">QApplication::saveState</a>(). All state data you are saving in thisfunction, should be marked with the session identifier <a href="qapplication.html#sessionId">QApplication::sessionId</a>(). This application specific identifier isglobally unique, so no clashes will occur. (See <a href="qsessionmanager.html">QSessionManager</a> forinformation on saving/restoring the state of a particular Qtapplication.)<p> Restoration is usually done in the application's main()function. Check if <a href="qapplication.html#isSessionRestored">QApplication::isSessionRestored</a>() is <tt>TRUE</tt>. Ifthat's the case, use the session identifier <a href="qapplication.html#sessionId">QApplication::sessionId</a>() again to access your state date and restorethe state of the application.<p> <strong>Important:</strong> In order to allow the window manager torestore window attributes such as stacking order or geometryinformation, you must identify your top level widgets with unique application-wide object names (see <a href="qobject.html#setName">QObject::setName</a>()). Whenrestoring the application, you must ensure that all restoredtop level widgets are given the same unique names they had before.<p> <h2> Testing and debugging session management </h2><a name="5"></a><p> Session management support on Mac OS X and Windows is fairly limiteddue to the lack of this functionality in the operating systemitself. Simply shut the session down and verify that your applicationbehaves as wanted. It may be a good idea to launch anotherapplication, usually the integrated development environment, beforestarting your application. This other application will get theshutdown message afterwards, thus permitting you to cancel theshutdown. Otherwise you would have to log in again after each testrun, which is not a problem per se but time consuming.<p> On Unix you can either use a desktop environment that supportsstandard X11R6 session management or, the recommended method, use thesession manager reference implementation provided by the X Consortium.This sample manager is called <tt>xsm</tt> and is part of a standard X11R6installation. As always with X11, a useful and informative manual pageis provided. Using <tt>xsm</tt> is straightforward (apart from the clumsyAthena-based user interface). Here's a simple approach:<p> <ul><li> Run X11R6.<li> Create a dot file <tt>.xsmstartup</tt> in your home directory whichcontains the single line<p> <pre>xterm</pre> <p> This tells <tt>xsm</tt> that the default/failsafe session is just an xtermand nothing else. Otherwise <tt>xsm</tt> would try to invoke lots ofclients including the windowmanager <tt>twm</tt>, which isn't very helpful.<li> Now launch <tt>xsm</tt> from another terminal window. Both a sessionmanager window and the xterm will appear. The xterm has a niceproperty that sets it apart from all the other shells you arecurrently running: within its shell, the <tt>SESSION_MANAGER</tt>environment variable points to the session manager you just started.<li> Launch your application from the new xterm window. It willconnect itself automatically to the session manager. You can checkwith the <em>ClientList</em> push button whether the connect was successful.<br><strong>Note:</strong> Never keep the <em>ClientList</em> open when youstart or end session managed clients! Otherwise <tt>xsm</tt> is likely tocrash.<li> Use the session manager's <em>Checkpoint</em> and <em>Shutdown</em> buttonswith different settings and see how your application behaves. The savetype <em>local</em> means that the clients should save their state. Itcorresponds to the <a href="qapplication.html#saveState">QApplication::saveState</a>() function. The <em>global</em> save type asks application to save their unsaved changes in thepermanent, globally accessible storage. It invokes <a href="qapplication.html#commitData">QApplication::commitData</a>().<li> Whenever something crashes, blame <tt>xsm</tt> and not Qt. <tt>xsm</tt> is farfrom being a usable session manager on a user's desktop. It is,however, stable and useful enough to serve as testing environment.</ul><p> <!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright © 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -