QSessionManager Class Reference |
Constant | Value | Description |
---|---|---|
QSessionManager::RestartIfRunning | 0 | if the application is still running when the session is shut down, it wants to be restarted at the start of the next session. |
QSessionManager::RestartAnyway | 1 | 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.) |
QSessionManager::RestartImmediately | 2 | the application wants to be started immediately whenever it is not running. |
QSessionManager::RestartNever | 3 | the application does not want to be restarted automatically. |
The default hint is RestartIfRunning.
Returns true if error interaction is permitted; otherwise returns false.
This is similar to allowsInteraction(), but also enables the application to tell the user about any errors that occur. Session managers may give error interaction requests 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.
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.
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.
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.)
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().
Here's an example of how an application's QApplication::commitData() might be implemented:
void MyApplication::commitData(QSessionManager& manager) { if (manager.allowsInteraction()) { int ret = QMessageBox::warning( mainWindow, tr("My Application"), tr("Save changes to document?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); switch (ret) { case QMessageBox::Save: manager.release(); if (!saveDocument()) manager.cancel(); break; case QMessageBox::Discard: break; case QMessageBox::Cancel: default: manager.cancel(); } } else { // we did not get permission to interact, then // do something reasonable instead } }
If an error occurred within the application while saving its data, you may want to try allowsErrorInteraction() instead.
See also QApplication::commitData(), release(), and cancel().
Tells the session manager to cancel the shutdown process. Applications should not call this function without first asking the user.
See also allowsInteraction() and allowsErrorInteraction().
Returns the currently set discard command.
To iterate over the list, you can use the foreach pseudo-keyword:
foreach (QString command, mySession.discardCommand()) do_something(command);
See also setDiscardCommand(), restartCommand(), and setRestartCommand().
Returns true if the session manager is currently performing a second session management phase; otherwise returns false.
See also requestPhase2().
Releases the session manager's interaction semaphore after an interaction phase.
See also allowsInteraction() and allowsErrorInteraction().
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.
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.
Note that if another application has requested a second phase it may get called before, simultaneously with, or after your application's second phase.
See also isPhase2().
Returns the currently set restart command.
To iterate over the list, you can use the foreach pseudo-keyword:
foreach (QString command, mySession.restartCommand()) do_something(command);
See also setRestartCommand() and restartHint().
Returns the application's current restart hint. The default is RestartIfRunning.
See also setRestartHint().
Returns the identifier of the current session.
If the application has been restored from an earlier session, this identifier is the same as it was in that earlier session.
See also sessionKey() and QApplication::sessionId().
Returns the session key in the current session.
If the application has been restored from an earlier session, this key is the same as it was when the previous session ended.
The session key changes with every call of commitData() or saveState().
See also sessionId() and QApplication::sessionKey().
Sets the discard command to the given list.
See also discardCommand() and setRestartCommand().
Low-level write access to the application's identification and state record are kept in the session manager.
The property called name has its value set to the string list value.
This is an overloaded member function, provided for convenience.
Low-level write access to the application's identification and state records are kept in the session manager.
The property called name has its value set to the string value.
If the session manager is capable of restoring sessions it will execute command in order to restore the application. The command defaults to
appname -session id
The -session 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.
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.
See also restartCommand(), setDiscardCommand(), and setRestartHint().
Sets the application's restart hint to hint. On application startup the hint is set to RestartIfRunning.
Note that these flags are only hints, a session manager may or may not respect them.
We recommend setting the restart hint in QApplication::saveState() because most session managers perform a checkpoint shortly after an application's startup.
See also restartHint().
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 4.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