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  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QDBusConnection Class Reference
[QtDBus module]

The QDBusConnection class represents a connection to the D-Bus bus daemon. More...

 #include <QDBusConnection>

This class was introduced in Qt 4.2.

Public Types

  • enum BusType { SessionBus, SystemBus, ActivationBus }
  • enum RegisterOption { ExportAdaptors, ExportScriptableSlots, ExportScriptableSignals, ExportScriptableProperties, ..., ExportChildObjects }
  • enum UnregisterMode { UnregisterNode, UnregisterTree }

Public Functions

  • QDBusConnection ( const QString & name )
  • QDBusConnection ( const QDBusConnection & other )
  • QString baseService () const
  • QDBusMessage call ( const QDBusMessage & message, QDBus::CallMode mode = QDBus::Block, int timeout = -1 ) const
  • bool callWithCallback ( const QDBusMessage & message, QObject * receiver, const char * returnMethod, const char * errorMethod, int timeout = -1 ) const
  • bool callWithCallback ( const QDBusMessage & message, QObject * receiver, const char * returnMethod, int timeout = -1 ) const   (deprecated)
  • bool connect ( const QString & service, const QString & path, const QString & interface, const QString & name, QObject * receiver, const char * slot )
  • bool connect ( const QString & service, const QString & path, const QString & interface, const QString & name, const QString & signature, QObject * receiver, const char * slot )
  • bool disconnect ( const QString & service, const QString & path, const QString & interface, const QString & name, QObject * receiver, const char * slot )
  • bool disconnect ( const QString & service, const QString & path, const QString & interface, const QString & name, const QString & signature, QObject * receiver, const char * slot )
  • QDBusConnectionInterface * interface () const
  • bool isConnected () const
  • QDBusError lastError () const
  • QObject * objectRegisteredAt ( const QString & path ) const
  • bool registerObject ( const QString & path, QObject * object, RegisterOptions options = ExportAdaptors )
  • bool registerService ( const QString & serviceName )
  • bool send ( const QDBusMessage & message ) const
  • void unregisterObject ( const QString & path, UnregisterMode mode = UnregisterNode )
  • bool unregisterService ( const QString & serviceName )
  • QDBusConnection & operator= ( const QDBusConnection & other )

Static Public Members

Related Non-Members


Detailed Description

The QDBusConnection class represents a connection to the D-Bus bus daemon.

This class is the initial point in a D-Bus session. Using it, you can get access to remote objects, interfaces; connect remote signals to your object's slots; register objects, etc.

D-Bus connections are created using the connectToBus() function, which opens a connection to the server daemon and does the initial handshaking, associating that connection with a name. Further attempts to connect using the same name will return the same connection.

The connection is then torn down using the disconnectFromBus() function.

As a convenience for the two most common connection types, the sessionBus() and systemBus() functions return open connections to the session server daemon and the system server daemon, respectively. Those connections are opened when first used and are closed when the QCoreApplication destructor is run.

D-Bus also supports peer-to-peer connections, without the need for a bus server daemon. Using this facility, two applications can talk to each other and exchange messages. This can be achieved by passing an address to connectToBus() function, which was opened by another D-Bus application using QDBusServer.


Member Type Documentation

enum QDBusConnection::BusType

Specifies the type of the bus connection. The valid bus types are:

ConstantValueDescription
QDBusConnection::SessionBus0the session bus, associated with the running desktop session
QDBusConnection::SystemBus1the system bus, used to communicate with system-wide processes
QDBusConnection::ActivationBus2the activation bus, the "alias" for the bus that started the service

On the Session Bus, one can find other applications by the same user that are sharing the same desktop session (hence the name). On the System Bus, however, processes shared for the whole system are usually found.

enum QDBusConnection::RegisterOption
flags QDBusConnection::RegisterOptions

Specifies the options for registering objects with the connection. The possible values are:

ConstantValueDescription
QDBusConnection::ExportAdaptors0x01export the contents of adaptors found in this object
QDBusConnection::ExportScriptableSlots0x10export this object's scriptable slots
QDBusConnection::ExportScriptableSignals0x20export this object's scriptable signals
QDBusConnection::ExportScriptableProperties0x40export this object's scriptable properties
QDBusConnection::ExportScriptableContents0xf0shorthand form for ExportScriptableSlots | ExportScriptableSignals | ExportScriptableProperties
QDBusConnection::ExportNonScriptableSlots0x100export this object's non-scriptable slots
QDBusConnection::ExportNonScriptableSignals0x200export this object's non-scriptable signals
QDBusConnection::ExportNonScriptableProperties0x400export this object's non-scriptable properties
QDBusConnection::ExportNonScriptableContents0xf00shorthand form for ExportNonScriptableSlots | ExportNonScriptableSignals | ExportNonScriptableProperties
QDBusConnection::ExportAllSlotsExportScriptableSlots | ExportNonScriptableSlotsexport all of this object's slots
QDBusConnection::ExportAllSignalsExportScriptableSignals | ExportNonScriptableSignalsexport all of this object's signals
QDBusConnection::ExportAllPropertiesExportScriptableProperties | ExportNonScriptablePropertiesexport all of this object's properties
QDBusConnection::ExportAllContentsExportScriptableContents | ExportNonScriptableContentsexport all of this object's contents
QDBusConnection::ExportChildObjects0x1000export this object's child objects

The RegisterOptions type is a typedef for QFlags<RegisterOption>. It stores an OR combination of RegisterOption values.

See also registerObject(), QDBusAbstractAdaptor, and Using adaptors.

enum QDBusConnection::UnregisterMode

The mode for unregistering an object path:

ConstantValueDescription
QDBusConnection::UnregisterNode0unregister this node only: do not unregister child objects
QDBusConnection::UnregisterTree1unregister this node and all its sub-tree

Note, however, if this object was registered with the ExportChildObjects option, UnregisterNode will unregister the child objects too.


Member Function Documentation

QDBusConnection::QDBusConnection ( const QString & name )

Creates a QDBusConnection object attached to the connection with name name.

This does not open the connection. You have to call connectToBus() to open it.

QDBusConnection::QDBusConnection ( const QDBusConnection & other )

Creates a copy of the other connection.

QDBusConnection::~QDBusConnection ()

Disposes of this object. This does not close the connection: you have to call disconnectFromBus() to do that.

QString QDBusConnection::baseService () const

Returns the unique connection name for this connection, if this QDBusConnection object is connected, or an empty QString otherwise.

A Unique Connection Name is a string in the form ":x.xxx" (where x are decimal digits) that is assigned by the D-Bus server daemon upon connection. It uniquely identifies this client in the bus.

This function returns an empty QString for peer-to-peer connections.

QDBusMessage QDBusConnection::call ( const QDBusMessage & message, QDBus::CallMode mode = QDBus::Block, int timeout = -1 ) const

Sends the message over this connection and blocks, waiting for a reply, for at most timeout milliseconds. This function is suitable for method calls only. It returns the reply message as its return value, which will be either of type QDBusMessage::ReplyMessage or QDBusMessage::ErrorMessage.

See the QDBusInterface::call() function for a more friendly way of placing calls.

Warning: If mode is QDBus::BlockWithGui, this function will reenter the Qt event loop in order to wait for the reply. During the wait, it may deliver signals and other method calls to your application. Therefore, it must be prepared to handle a reentrancy whenever a call is placed with call().

bool QDBusConnection::callWithCallback ( const QDBusMessage & message, QObject * receiver, const char * returnMethod, const char * errorMethod, int timeout = -1 ) const

Sends the message over this connection and returns immediately. When the reply is received, the method returnMethod is called in the receiver object. If an error occurs, the method errorMethod will be called instead.

If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds).

This function is suitable for method calls only. It is guaranteed that the slot will be called exactly once with the reply, as long as the parameter types match and no error occurs.

Returns true if the message was sent, or false if the message could not be sent.

bool QDBusConnection::callWithCallback ( const QDBusMessage & message, QObject * receiver, const char * returnMethod, int timeout = -1 ) const

This function is deprecated.

This is an overloaded member function, provided for convenience.

Sends the message over this connection and returns immediately. When the reply is received, the method returnMethod is called in the receiver object.

This function is suitable for method calls only. It is guaranteed that the slot will be called exactly once with the reply, as long as the parameter types match and no error occurs.

This function is dangerous because it cannot report errors, including the expiration of the timeout.

Returns true if the message was sent, or false if the message could not be sent.

bool QDBusConnection::connect ( const QString & service, const QString & path, const QString & interface, const QString & name, QObject * receiver, const char * slot )

Connects the signal specified by the service, path, interface and name parameters to the slot slot in object receiver. The arguments service and path can be empty, denoting a connection to any signal of the (interface, name) pair, from any remote application.

Returns true if the connection was successful.

Warning: The signal will only be delivered to the slot if the parameters match. This verification can be done only when the signal is received, not at connection time.

bool QDBusConnection::connect ( const QString & service, const QString & path, const QString & interface, const QString & name, const QString & signature, QObject * receiver, const char * slot )

This is an overloaded member function, provided for convenience.

Connects the signal to the slot slot in object receiver. Unlike the other connect() overload, this function allows one to specify the parameter signature to be connected using the signature variable. The function will then verify that this signature can be delivered to the slot specified by slot and return false otherwise.

Note: This function verifies that the signal signature matches the slot's parameters, but it does not verify that the actual signal exists with the given signature in the remote service.

QDBusConnection QDBusConnection::connectToBus ( BusType type, const QString & name )   [static]

Opens a connection of type type to one of the known busses and associate with it the connection name name. Returns a QDBusConnection object associated with that connection.

QDBusConnection QDBusConnection::connectToBus ( const QString & address, const QString & name )   [static]

This is an overloaded member function, provided for convenience.

Opens a peer-to-peer connection on address address and associate with it the connection name name. Returns a QDBusConnection object associated with that connection.

bool QDBusConnection::disconnect ( const QString & service, const QString & path, const QString & interface, const QString & name, QObject * receiver, const char * slot )

Disconnects the signal specified by the service, path, interface and name parameters from the slot slot in object receiver. The arguments service and path can be empty, denoting a disconnection from all signals of the (interface, name) pair, from all remote applications.

Returns true if the disconnection was successful.

bool QDBusConnection::disconnect ( const QString & service, const QString & path, const QString & interface, const QString & name, const QString & signature, QObject * receiver, const char * slot )

This is an overloaded member function, provided for convenience.

Disconnects the signal from the slot slot in object receiver. Unlike the other disconnect() overload, this function allows one to specify the parameter signature to be disconnected using the signature variable. The function will then verify that this signature is connected to the slot specified by slot and return false otherwise.

void QDBusConnection::disconnectFromBus ( const QString & name )   [static]

Closes the connection of name name.

Note that if there are still QDBusConnection objects associated with the same connection, the connection will not be closed until all references are dropped. However, no further references can be created using the QDBusConnection constructor.

QDBusConnectionInterface * QDBusConnection::interface () const

Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connection.

bool QDBusConnection::isConnected () const

Returns true if this QDBusConnection object is connected.

If it isn't connected, calling connectToBus() on the same connection name will not make be connected. You need to call the QDBusConnection constructor again.

QDBusError QDBusConnection::lastError () const

Returns the last error that happened in this connection.

This function is provided for low-level code. If you're using QDBusInterface::call(), error codes are reported by its return value.

See also QDBusInterface and QDBusMessage.

QObject * QDBusConnection::objectRegisteredAt ( const QString & path ) const

Return the object that was registered with the registerObject() at the object path given by path.

bool QDBusConnection::registerObject ( const QString & path, QObject * object, RegisterOptions options = ExportAdaptors )

Registers the object object at path path and returns true if the registration was successful. The options parameter specifies how much of the object object will be exposed through D-Bus.

This function does not replace existing objects: if there is already an object registered at path path, this function will return false. Use unregisterObject() to unregister it first.

You cannot register an object as a child object of an object that was registered with QDBusConnection::ExportChildObjects.

bool QDBusConnection::registerService ( const QString & serviceName )

Attempts to register the serviceName on the D-Bus server and returns true if the registration succeded. The registration will fail if the name is already registered by another application.

See also unregisterService() and QDBusConnectionInterface::registerService().

bool QDBusConnection::send ( const QDBusMessage & message ) const

Sends the message over this connection, without waiting for a reply. This is suitable for errors, signals, and return values as well as calls whose return values are not necessary.

Returns true if the message was queued successfully, false otherwise.

QDBusConnection QDBusConnection::sender ()   [static]

Returns the connection that sent the signal, if called in a slot activated by QDBus; otherwise it returns 0.

QDBusConnection QDBusConnection::sessionBus ()   [static]

Returns a QDBusConnection object opened with the session bus. The object reference returned by this function is valid until the QCoreApplication's destructor is run, when the connection will be closed and the object, deleted.

QDBusConnection QDBusConnection::systemBus ()   [static]

Returns a QDBusConnection object opened with the system bus. The object reference returned by this function is valid until the QCoreApplication's destructor is run, when the connection will be closed and the object, deleted.

void QDBusConnection::unregisterObject ( const QString & path, UnregisterMode mode = UnregisterNode )

Unregisters an object that was registered with the registerObject() at the object path given by path and, if mode is QDBusConnection::UnregisterTree, all of its sub-objects too.

Note that you cannot unregister objects that were not registered with registerObject().

bool QDBusConnection::unregisterService ( const QString & serviceName )

Unregisters the service serviceName that was previously registered with registerService() and returns true if it succeeded.

See also registerService() and QDBusConnectionInterface::unregisterService().

QDBusConnection & QDBusConnection::operator= ( const QDBusConnection & other )

Creates a copy of the connection other in this object. Note that the connection this object referenced before the copy, is not spontaneously disconnected.

See also disconnectFromBus().


Related Non-Members

QDBusConnection QDBusConnection::sessionBus ()   [static]

Returns a QDBusConnection object opened with the session bus. The object reference returned by this function is valid until the QCoreApplication's destructor is run, when the connection will be closed and the object, deleted.

QDBusConnection QDBusConnection::systemBus ()   [static]

Returns a QDBusConnection object opened with the system bus. The object reference returned by this function is valid until the QCoreApplication's destructor is run, when the connection will be closed and the object, deleted.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 12
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Developer Network au hasard

Logo

Compiler l'add-in Qt de Visual Studio

Le Qt Developer Network est un réseau de développeurs Qt anglophone, où ils peuvent partager leur expérience sur le framework. 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 4.4
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