Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QSessionManager Class Reference

The QSessionManager class provides access to the session manager. More...

#include <qsessionmanager.h>

Inherits QObject.

List of all member functions.

Public Members


Detailed Description

The QSessionManager class provides access to the session manager.

The session manager is responsible for session management, most importantly for interruption and resumption. A "session" is a kind of record of the state of the system, e.g. which applications were run at start up and which applications are currently running. The session manager is used to save the session, e.g. when the machine is shut down; and to restore a session, e.g. when the machine is started up. Use QSettings to save and restore an individual application's settings, e.g. window positions, recently used files, etc.

QSessionManager provides an interface between the application and the session manager so that the program can work well with the session manager. In Qt, session management requests for action are handled by the two virtual functions QApplication::commitData() and QApplication::saveState(). Both provide a reference to a session manager object as argument, to allow the application to communicate with the session manager.

During a session management action (i.e. within commitData() and saveState()), no user interaction is possible unless the application got explicit permission from the session manager. You ask for permission by calling allowsInteraction() or, if it's really urgent, allowsErrorInteraction(). Qt does not enforce this, but the session manager may.

You can try to abort the shutdown process by calling cancel(). The default commitData() function does this if some top-level window rejected its closeEvent().

For sophisticated session managers provided on Unix/X11, QSessionManager offers further possibilites to fine-tune an application's session management behavior: setRestartCommand(), setDiscardCommand(), setRestartHint(), setProperty(), requestPhase2(). See the respective function descriptions for further details.

See also Main Window and Related Classes and Environment Classes.


Member Type Documentation

QSessionManager::RestartHint

This enum type defines the circumstances under which this application wants to be restarted by the session manager. The current values are

  • QSessionManager::RestartIfRunning - 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 - 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 - the application wants to be started immediately whenever it is not running.
  • QSessionManager::RestartNever - the application does not want to be restarted automatically.

The default hint is RestartIfRunning.


Member Function Documentation

bool QSessionManager::allowsErrorInteraction ()

This is similar to allowsInteraction(), but also tells the session manager that an error occurred. Session managers may give error interaction request 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().

bool QSessionManager::allowsInteraction ()

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& sm ) {
    if ( sm.allowsInteraction() ) {
        switch ( QMessageBox::warning(
                    yourMainWindow,
                    tr("Application Name"),
                    tr("Save changes to document Foo?"),
                    tr("&Yes"),
                    tr("&No"),
                    tr("Cancel"),
                    0, 2) ) {
        case 0: // yes
            sm.release();
            // save document here; if saving fails, call sm.cancel()
            break;
        case 1: // continue without saving
            break;
        default: // cancel
            sm.cancel();
            break;
        }
    } 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().

void QSessionManager::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().

QStringList QSessionManager::discardCommand () const

Returns the currently set discard command.

Note that if you want to iterate over the list, you should iterate over a copy, e.g.

    QStringList list = mySession.discardCommand();
    QStringList::Iterator it = list.begin();
    while( it != list.end() ) {
        myProcessing( *it );
        ++it;
    }
    

See also setDiscardCommand(), restartCommand() and setRestartCommand().

void * QSessionManager::handle () const

X11 only: returns a handle to the current SmcConnection.

bool QSessionManager::isPhase2 () const

Returns TRUE if the session manager is currently performing a second session management phase; otherwise returns FALSE.

See also requestPhase2().

void QSessionManager::release ()

Releases the session manager's interaction semaphore after an interaction phase.

See also allowsInteraction() and allowsErrorInteraction().

void QSessionManager::requestPhase2 ()

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().

QStringList QSessionManager::restartCommand () const

Returns the currently set restart command.

Note that if you want to iterate over the list, you should iterate over a copy, e.g.

    QStringList list = mySession.restartCommand();
    QStringList::Iterator it = list.begin();
    while( it != list.end() ) {
        myProcessing( *it );
        ++it;
    }
    

See also setRestartCommand() and restartHint().

RestartHint QSessionManager::restartHint () const

Returns the application's current restart hint. The default is RestartIfRunning.

See also setRestartHint().

QString QSessionManager::sessionId () const

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 QApplication::sessionId().

void QSessionManager::setDiscardCommand ( const QStringList & )

See also discardCommand() and setRestartCommand().

void QSessionManager::setManagerProperty ( const QString & name, const QStringList & value )

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.

void QSessionManager::setManagerProperty ( const QString & name, const QString & value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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.

void QSessionManager::setRestartCommand ( const QStringList & command )

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().

void QSessionManager::setRestartHint ( RestartHint hint )

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().


This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 56
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 97
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 32
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 231
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 103
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le Qt Labs au hasard

Logo

QLocale : à propos du temps (et des dates, et des langues, et des...)

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

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 3.0
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 !
 
 
 
 
Partenaires

Hébergement Web