|  | Home · All Classes · Modules

# QDBusConnectionInterface Class Reference
[QtDBus module]

The QDBusConnectionInterface class provides access to the D-Bus bus daemon service. More...

Inherits QDBusAbstractInterface.

### Types

- enum RegisterServiceReply { ServiceNotRegistered, ServiceRegistered, ServiceQueued }
- enum ServiceQueueOptions { DontQueueService, QueueService, ReplaceExistingService }
- enum ServiceReplacementOptions { DontAllowReplacement, AllowReplacement }

### Methods

- connectNotify (self, SIGNAL())
- disconnectNotify (self, SIGNAL())
- QDBusReply isServiceRegistered (self, QString serviceName)
- QDBusReply registeredServiceNames (self)
- QDBusReply registerService (self, QString serviceName, ServiceQueueOptions qoption = QDBusConnectionInterface.DontQueueService, ServiceReplacementOptions roption = QDBusConnectionInterface.DontAllowReplacement)
- QDBusReply serviceOwner (self, QString name)
- QDBusReply servicePid (self, QString serviceName)
- QDBusReply serviceUid (self, QString serviceName)
- QDBusReply startService (self, QString name)
- QDBusReply unregisterService (self, QString serviceName)

### Qt Signals

- void callWithCallbackFailed (const QDBusError&,const QDBusMessage&)
- void serviceOwnerChanged (const QString&,const QString&,const QString&)
- void serviceRegistered (const QString&)
- void serviceUnregistered (const QString&)

## Detailed Description

The QDBusConnectionInterface class provides access to the D-Bus bus daemon service.

The D-Bus bus server daemon provides one special interface `org.freedesktop.DBus` that allows clients to access certain properties of the bus, such as the current list of clients connected. The QDBusConnectionInterface class provides access to that interface.

The most common uses of this class are to register and unregister service names on the bus using the registerService() and unregisterService() functions, query about existing names using the isServiceRegistered(), registeredServiceNames() and serviceOwner() functions, and to receive notification that a client has registered or de-registered through the serviceRegistered(), serviceUnregistered() and serviceOwnerChanged() signals.

## Type Documentation

### QDBusConnectionInterface.RegisterServiceReply

The possible return values from registerService():

Constant | Value | Description
--- | --- | ---
`QDBusConnectionInterface.ServiceNotRegistered` | `0` | The call failed and the service name was not registered.
`QDBusConnectionInterface.ServiceRegistered` | `1` | The caller is now the owner of the service name.
`QDBusConnectionInterface.ServiceQueued` | `2` | The caller specified the QueueService flag and the service was already registered, so we are in queue.

The serviceRegistered() signal will be emitted when the service is acquired by this application.

### QDBusConnectionInterface.ServiceQueueOptions

Flags for determining how a service registration should behave, in case the service name is already registered.

Constant | Value | Description
--- | --- | ---
`QDBusConnectionInterface.DontQueueService` | `0` | If an application requests a name that is already owned, no queueing will be performed. The registeredService() call will simply fail. This is the default.
`QDBusConnectionInterface.QueueService` | `1` | Attempts to register the requested service, but do not try to replace it if another application already has it registered. Instead, simply put this application in queue, until it is given up. The serviceRegistered() signal will be emitted when that happens.
`QDBusConnectionInterface.ReplaceExistingService` | `2` | If another application already has the service name registered, attempt to replace it.

See also ServiceReplacementOptions.

### QDBusConnectionInterface.ServiceReplacementOptions

Flags for determining if the D-Bus server should allow another application to replace a name that this application has registered with the ReplaceExistingService option.

The possible values are:

Constant | Value | Description
--- | --- | ---
`QDBusConnectionInterface.DontAllowReplacement` | `0` | Do not allow another application to replace us. The service must be explicitly unregistered with unregisterService() for another application to acquire it. This is the default.
`QDBusConnectionInterface.AllowReplacement` | `1` | Allow other applications to replace us with the ReplaceExistingService option to registerService() without intervention. If that happens, the serviceUnregistered() signal will be emitted.

See also ServiceQueueOptions.

## Method Documentation

### QDBusConnectionInterface.connectNotify (self, SIGNAL())

### QDBusConnectionInterface.disconnectNotify (self, SIGNAL())

### QDBusReply QDBusConnectionInterface.isServiceRegistered (self, QString serviceName)

Returns true if the service name serviceName has is currently registered.

### QDBusReply QDBusConnectionInterface.registeredServiceNames (self)

### QDBusReply QDBusConnectionInterface.registerService (self, QString serviceName, ServiceQueueOptions qoption = QDBusConnectionInterface.DontQueueService, ServiceReplacementOptions roption = QDBusConnectionInterface.DontAllowReplacement)

Requests to register the service name serviceName on the bus. The qoption flag specifies how the D-Bus server should behave if serviceName is already registered. The roption flag specifies if the server should allow another application to replace our registered name.

If the service registration succeeds, the serviceRegistered() signal will be emitted. If we are placed in queue, the signal will be emitted when we obtain the name. If roption is AllowReplacement, the serviceUnregistered() signal will be emitted if another application replaces this one.

See also unregisterService().

### QDBusReply QDBusConnectionInterface.serviceOwner (self, QString name)

Returns the unique connection name of the primary owner of the name name. If the requested name doesn't have an owner, returns a `org.freedesktop.DBus.Error.NameHasNoOwner` error.

### QDBusReply QDBusConnectionInterface.servicePid (self, QString serviceName)

Returns the Unix Process ID (PID) for the process currently holding the bus service serviceName.

### QDBusReply QDBusConnectionInterface.serviceUid (self, QString serviceName)

Returns the Unix User ID (UID) for the process currently holding the bus service serviceName.

### QDBusReply QDBusConnectionInterface.startService (self, QString name)

Requests that the bus start the service given by the name name.

### QDBusReply QDBusConnectionInterface.unregisterService (self, QString serviceName)

Releases the claim on the bus service name serviceName, that had been previously registered with registerService(). If this application had ownership of the name, it will be released for other applications to claim. If it only had the name queued, it gives up its position in the queue.

## Qt Signal Documentation

### void callWithCallbackFailed (const QDBusError&,const QDBusMessage&)

This is the default overload of this signal.

This signal is emitted when there is an error during a QDBusConnection.callWithCallback(). error specifies the error. call is the message that couldn't be delivered.

See also QDBusConnection.callWithCallback().

### void serviceOwnerChanged (const QString&,const QString&,const QString&)

This is the default overload of this signal.

This signal is emitted by the D-Bus server whenever a service ownership change happens in the bus, including apparition and disparition of names.

This signal means the application oldOwner lost ownership of bus name name to application newOwner. If oldOwner is an empty string, it means the name name has just been created; if newOwner is empty, the name name has no current owner and is no longer available.

Note: connecting to this signal will make the application listen for and receive every single service ownership change on the bus. Depending on how many services are running, this make the application be activated to receive more signals than it needs. To avoid this problem, use the QDBusServiceWatcher class, which can listen for specific changes.

### void serviceRegistered (const QString&)

This is the default overload of this signal.

This signal is emitted by the D-Bus server when the bus service name (unique connection name or well-known service name) given by serviceName is acquired by this application.

Acquisition happens after this application has requested a name using registerService().

### void serviceUnregistered (const QString&)

This is the default overload of this signal.

This signal is emitted by the D-Bus server when this application loses ownership of the bus service name given by serviceName.