6.0.0-rc4Source

QDBusConnectionInterface Class

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

Header#include <QDBusConnectionInterface>
CMaketarget_link_libraries(app PRIVATE Nt::DBus)
ModuleNt D-Bus C++ Classes
InheritsQDBusAbstractInterface

List of all members, including inherited members

Public Types

Public Functions

QDBusReply<QStringList>registeredServiceNames() const
QDBusReply<QStringList>activatableServiceNames() const
QDBusReply<bool>isServiceRegistered(const QString &serviceName) const
QDBusReply<QString>serviceOwner(const QString &name) const
QDBusReply<bool>unregisterService(const QString &serviceName)
QDBusReply<QDBusConnectionInterface::RegisterServiceReply>registerService(const QString &serviceName, ServiceQueueOptions qoption = DontQueueService, ServiceReplacementOptions roption = DontAllowReplacement)
QDBusReply<uint>servicePid(const QString &serviceName) const
QDBusReply<uint>serviceUid(const QString &serviceName) const
QDBusReply<void>startService(const QString &name)

Signals

voidserviceRegistered(const QString &service)
voidserviceUnregistered(const QString &service)
voidserviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)
voidcallWithCallbackFailed(const QDBusError &error, const QDBusMessage &call)

Detailed Description

QDBusConnection::interface() returns the one of a connection. It lists and looks up the names on the bus, claims and releases names, and reports names that appear and disappear:

QDBusConnectionInterface *bus = QDBusConnection::sessionBus().interface();
if (bus->isServiceRegistered("org.example.Clock"))
    qDebug() << "owned by" << bus->serviceOwner("org.example.Clock").value();

See also QDBusConnection and QDBusServiceWatcher.

Differences from Qt

The object lives in the thread that does the connection's I/O, so its signals reach other threads through queued connections. It listens for every NameOwnerChanged signal of the bus from the moment it is created. The NameAcquired and NameLost signals are not available.

Member Type Documentation

enum QDBusConnectionInterface::RegisterServiceReply

ConstantDescription
QDBusConnectionInterface::ServiceNotRegisteredThe name was not claimed.
QDBusConnectionInterface::ServiceRegisteredThis connection owns the name.
QDBusConnectionInterface::ServiceQueuedThis connection waits in the queue for the name.

enum QDBusConnectionInterface::ServiceQueueOptions

What registerService() does when the name is taken.

ConstantDescription
QDBusConnectionInterface::DontQueueServiceFail.
QDBusConnectionInterface::QueueServiceWait in the queue for the name.
QDBusConnectionInterface::ReplaceExistingServiceTake the name if its owner allows replacement; otherwise fail.

enum QDBusConnectionInterface::ServiceReplacementOptions

ConstantDescription
QDBusConnectionInterface::DontAllowReplacementOther connections cannot take the name away.
QDBusConnectionInterface::AllowReplacementAnother connection may take the name with ReplaceExistingService.

Member Function Documentation

QDBusReply<QStringList> QDBusConnectionInterface::activatableServiceNames() const

Returns the names that the bus can start a program for.

[signal] void QDBusConnectionInterface::callWithCallbackFailed(const QDBusError &error, const QDBusMessage &call)

This signal is emitted when QDBusConnection::callWithCallback() fails to deliver the result of call, with the error that occurred.

QDBusReply<bool> QDBusConnectionInterface::isServiceRegistered(const QString &serviceName) const

Returns whether a connection owns serviceName.

QDBusReply<QStringList> QDBusConnectionInterface::registeredServiceNames() const

Returns the names that exist on the bus, unique and well-known.

QDBusReply<QDBusConnectionInterface::RegisterServiceReply> QDBusConnectionInterface::registerService(const QString &serviceName, ServiceQueueOptions qoption = DontQueueService, ServiceReplacementOptions roption = DontAllowReplacement)

Claims serviceName. qoption says what happens if the name is taken, and roption whether others may take it away later.

QDBusReply<QString> QDBusConnectionInterface::serviceOwner(const QString &name) const

Returns the unique name of the connection that owns name.

[signal] void QDBusConnectionInterface::serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner)

This signal is emitted when the owner of name changes from oldOwner to newOwner.

QDBusReply<uint> QDBusConnectionInterface::servicePid(const QString &serviceName) const

Returns the process id of the connection that owns serviceName.

[signal] void QDBusConnectionInterface::serviceRegistered(const QString &service)

This signal is emitted when service gets its first owner.

QDBusReply<uint> QDBusConnectionInterface::serviceUid(const QString &serviceName) const

Returns the user id of the connection that owns serviceName.

[signal] void QDBusConnectionInterface::serviceUnregistered(const QString &service)

This signal is emitted when service loses its last owner.

QDBusReply<void> QDBusConnectionInterface::startService(const QString &name)

Asks the bus to start the program that provides name.

QDBusReply<bool> QDBusConnectionInterface::unregisterService(const QString &serviceName)

Releases serviceName. The value is true if this connection owned it.