📄 qsessionmanager.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/src/kernel/qapplication.cpp:3422 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QSessionManager Class</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>QSessionManager Class Reference</h1><p>The QSessionManager class provides access to the session manager.<a href="#details">More...</a><p><tt>#include <<a href="qsessionmanager-h.html">qsessionmanager.h</a>></tt><p>Inherits <a href="qobject.html">QObject</a>.<p><a href="qsessionmanager-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn>QString <a href="#sessionId"><b>sessionId</b></a> () const</div></li><li><div class=fn>void * <a href="#handle"><b>handle</b></a> () const</div></li><li><div class=fn>bool <a href="#allowsInteraction"><b>allowsInteraction</b></a> ()</div></li><li><div class=fn>bool <a href="#allowsErrorInteraction"><b>allowsErrorInteraction</b></a> ()</div></li><li><div class=fn>void <a href="#release"><b>release</b></a> ()</div></li><li><div class=fn>void <a href="#cancel"><b>cancel</b></a> ()</div></li><li><div class=fn>enum <a href="#RestartHint-enum"><b>RestartHint</b></a> { RestartIfRunning, RestartAnyway, RestartImmediately, RestartNever }</div></li><li><div class=fn>void <a href="#setRestartHint"><b>setRestartHint</b></a> ( RestartHint hint )</div></li><li><div class=fn>RestartHint <a href="#restartHint"><b>restartHint</b></a> () const</div></li><li><div class=fn>void <a href="#setRestartCommand"><b>setRestartCommand</b></a> ( const QStringList & command )</div></li><li><div class=fn>QStringList <a href="#restartCommand"><b>restartCommand</b></a> () const</div></li><li><div class=fn>void <a href="#setDiscardCommand"><b>setDiscardCommand</b></a> ( const QStringList & )</div></li><li><div class=fn>QStringList <a href="#discardCommand"><b>discardCommand</b></a> () const</div></li><li><div class=fn>void <a href="#setManagerProperty-2"><b>setManagerProperty</b></a> ( const QString & name, const QString & value )</div></li><li><div class=fn>void <a href="#setManagerProperty"><b>setManagerProperty</b></a> ( const QString & name, const QStringList & value )</div></li><li><div class=fn>bool <a href="#isPhase2"><b>isPhase2</b></a> () const</div></li><li><div class=fn>void <a href="#requestPhase2"><b>requestPhase2</b></a> ()</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QSessionManager class provides access to the session manager.<p> <p> The session manager is responsible for session management, mostimportantly for interruption and resumption. A "session" is a kindof record of the state of the system, e.g. which applications wererun at start up and which applications are currently running. Thesession manager is used to save the session, e.g. when the machineis shut down; and to restore a session, e.g. when the machine isstarted up. Use <a href="qsettings.html">QSettings</a> to save and restore an individualapplication's settings, e.g. window positions, recently used files,etc.<p> QSessionManager provides an interface between the application andthe session manager so that the program can work well with thesession manager. In Qt, session management requests for actionare handled by the two virtual functions <a href="qapplication.html#commitData">QApplication::commitData</a>()and <a href="qapplication.html#saveState">QApplication::saveState</a>(). Both provide a reference toa session manager object as argument, to allow the applicationto communicate with the session manager.<p> During a session management action (i.e. within commitData() andsaveState()), no user interaction is possible <em>unless</em> theapplication got explicit permission from the session manager. Youask for permission by calling <a href="#allowsInteraction">allowsInteraction</a>() or, if it's reallyurgent, <a href="#allowsErrorInteraction">allowsErrorInteraction</a>(). Qt does not enforce this, but thesession manager may.<p> You can try to abort the shutdown process by calling <a href="#cancel">cancel</a>(). Thedefault commitData() function does this if some top-level windowrejected its closeEvent().<p> For sophisticated session managers provided on Unix/X11, QSessionManageroffers further possibilites to fine-tune an application's sessionmanagement behavior: <a href="#setRestartCommand">setRestartCommand</a>(), <a href="#setDiscardCommand">setDiscardCommand</a>(),<a href="#setRestartHint">setRestartHint</a>(), <a href="qobject.html#setProperty">setProperty</a>(), <a href="#requestPhase2">requestPhase2</a>(). See the respectivefunction descriptions for further details.<p>See also <a href="application.html">Main Window and Related Classes</a> and <a href="environment.html">Environment Classes</a>.<hr><h2>Member Type Documentation</h2><h3 class=fn><a name="RestartHint-enum"></a>QSessionManager::RestartHint</h3> <p> This enum type defines the circumstances under which thisapplication wants to be restarted by the session manager. Thecurrent values are<ul><li><tt>QSessionManager::RestartIfRunning</tt> - if the application is still running whenthe session is shut down, it wants to be restarted at the start ofthe next session.<li><tt>QSessionManager::RestartAnyway</tt> - the application wants to be started at thestart of the next session, no matter what. (This is useful forutilities that run just after startup and then quit.)<li><tt>QSessionManager::RestartImmediately</tt> - the application wants to be startedimmediately whenever it is not running.<li><tt>QSessionManager::RestartNever</tt> - the application does not want to be restartedautomatically.</ul><p> The default hint is <a href="#RestartHint-enum">RestartIfRunning</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn>bool <a name="allowsErrorInteraction"></a>QSessionManager::allowsErrorInteraction ()</h3><p> This is similar to <a href="#allowsInteraction">allowsInteraction</a>(), but also tells the sessionmanager that an error occurred. Session managers may give errorinteraction request higher priority, which means that it is more likelythat an error interaction is permitted. However, you are still notguaranteed that the session manager will allow interaction.<p> <p>See also <a href="#allowsInteraction">allowsInteraction</a>(), <a href="#release">release</a>() and <a href="#cancel">cancel</a>().<h3 class=fn>bool <a name="allowsInteraction"></a>QSessionManager::allowsInteraction ()</h3><p> Asks the session manager for permission to interact with theuser. Returns TRUE if interaction is permitted; otherwisereturns FALSE.<p> The rationale behind this mechanism is to make it possible tosynchronize user interaction during a shutdown. Advanced sessionmanagers may ask all applications simultaneously to commit theirdata, resulting in a much faster shutdown.<p> When the interaction is completed we strongly recommend releasing theuser interaction semaphore with a call to <a href="#release">release</a>(). This way, otherapplications may get the chance to interact with the user while yourapplication is still busy saving data. (The semaphore is implicitlyreleased when the application exits.)<p> If the user decides to cancel the shutdown process during theinteraction phase, you must tell the session manager that this hashappened by calling <a href="#cancel">cancel</a>().<p> Here's an example of how an application's <a href="qapplication.html#commitData">QApplication::commitData</a>()might be implemented:<p> <pre>void MyApplication::commitData( QSessionManager& sm ) { if ( sm.<a href="#allowsInteraction">allowsInteraction</a>() ) { switch ( QMessageBox::<a href="qmessagebox.html#warning">warning</a>( yourMainWindow, <a href="qobject.html#tr">tr</a>("Application Name"), <a href="qobject.html#tr">tr</a>("Save changes to document Foo?"), <a href="qobject.html#tr">tr</a>("&Yes"), <a href="qobject.html#tr">tr</a>("&No"), <a href="qobject.html#tr">tr</a>("Cancel"), 0, 2) ) { case 0: // yes sm.<a href="#release">release</a>(); // save document here; if saving fails, call sm.<a href="#cancel">cancel</a>() break; case 1: // continue without saving break; default: // cancel sm.<a href="#cancel">cancel</a>(); break; } } else { // we did not get permission to interact, then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -