⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit -  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: white; color: black; }--></style></head><body bgcolor="#ffffff"><p><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b>  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align="center"> Session Management</h1><br clear="all"><h2> Definitions </h2><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 his desktop at a time. Under Unix/X11, however, asession may as well run on different computers, span multiple displaysor just consists of a few applications.<p><h2> Shutting a session down </h2><p>A session is shut down by the session manager, usually on behalf ofthe user when she wants to log out. A system might, however, alsoperform an automatic shutdown in an emergency case, when for examplethe power is about to be lost. Clearly there is one big differencebetween both shutdowns. During the first, the user may want tointeract with the application, telling 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><p>On MS-Windows, there is nothing like complete session management forapplications yet, i.e. no restoring of previous sessions.  Windows does,however, support graceful logouts where applications have the chanceto cancel the process after getting confirmation from the user. Thisis the functionality that corresponds to the<a href="qapplication.html#6163c1">QApplication::commitData()</a> method.<p>X11 on the other hand supports complete session management sinceX11R6. Within the life-time of Qt-2.0, virtually all popular Unix/X11desktops will very likely support the XConsortium standard.<p><h2> Getting session management to work with Qt </h2><p>In any case you should reimplement <a href="qapplication.html#6163c1">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 onshutdown"></center><p>Example code to this dialog can be found in the documentation of <a href="qsessionmanager.html#25f903">QSessionManager::allowsInteraction()</a>.<p>For complete session management yet only supported on X11R6, 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#437e1b">QApplication::saveState()</a>. All state data you are saving in thisfunction, shall be marked with the session identifier <a href="qapplication.html#a6fd61">QApplication::sessionId()</a>. This application specific identifier isglobally unique, so no clashes will happen.<p>Restauration is usually done in the application's main()function. Check if <a href="qapplication.html#aa8893">QApplication::isSessionRestored()</a> is <code>TRUE.</code> Ifthat's the case, use the session identifier <a href="qapplication.html#a6fd61">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 have to identify your toplevel widgets with anapplication-wide unique object name (see <a href="qobject.html#ceac81">QObject::setName()</a> ). Whenrestoring the application, you'll have to ensure that all restoredtoplevel widgets end up with their prior object name again.<p><h2> Testing and debugging session management </h2><p>As mentioned earlier, session management support on Windows is fairlylimited due to the lack of this functionality in the Windows operatingsystem itself. Simply shut the session down and verify that yourapplication behaves 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 dubbed <code>xsm</code> and is part of a standard X11R6installation. As always with X11, a useful and informative manual pageis provided. Using <code>xsm</code> is straightforward (apart from the clumsyAthena-based user interface). Here's a simple approach:<p><ul><li> Run X11R6.<li> Create a dot file <code>.xsmstartup</code> in your home directory whichcontains the single line<p><pre>xterm</pre><p>This tells <code>xsm</code> that the default/failsafe session is just an xtermand nothing else. Otherwise <code>xsm</code> would try to invoke lots ofclients including the windowmanager <code>twm,</code> which isn't very helpful.<li> Now launch <code>xsm</code> 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 <code>SESSION_MANAGER</code>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 <code>xsm</code> 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#437e1b">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#6163c1">QApplication::commitData()</a>, respectively.<li> Whenever something crashes, blame <code>xsm</code> and not Qt. <code>xsm</code> 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><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -