6.0.0-rc4Source

QDBusServiceWatcher Class

The QDBusServiceWatcher class allows the user to watch for a bus service change. More…

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

List of all members, including inherited members

Public Types

Public Functions

QDBusServiceWatcher(QObject *parent = nullptr)
QDBusServiceWatcher(const QString &service, const QDBusConnection &connection, WatchMode watchMode = WatchForOwnerChange, QObject *parent = nullptr)
~QDBusServiceWatcher()
QStringListwatchedServices() const
voidsetWatchedServices(const QStringList &services)
voidaddWatchedService(const QString &newService)
boolremoveWatchedService(const QString &service)
WatchModewatchMode() const
voidsetWatchMode(WatchMode mode)
QDBusConnectionconnection() const
voidsetConnection(const QDBusConnection &connection)

Signals

voidserviceRegistered(const QString &service)
voidserviceUnregistered(const QString &service)
voidserviceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)

Detailed Description

A watcher reports when the names it watches get or lose an owner:

QDBusServiceWatcher watcher("org.example.Clock", QDBusConnection::sessionBus(),
                            QDBusServiceWatcher::WatchForUnregistration);
QObject::connect(&watcher, &QDBusServiceWatcher::serviceUnregistered,
                 [](const QString &name) { qDebug() << name << "went away"; });

A name that ends in .* watches every name below it, such as org.example.*.

See also QDBusConnectionInterface.

Differences from Qt

None.

Member Type Documentation

typedef QDBusServiceWatcher::WatchMode

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

enum QDBusServiceWatcher::WatchModeFlag

ConstantDescription
QDBusServiceWatcher::WatchForRegistrationReport names that get an owner.
QDBusServiceWatcher::WatchForUnregistrationReport names that lose their owner.
QDBusServiceWatcher::WatchForOwnerChangeReport every change of owner.

Member Function Documentation

[explicit] QDBusServiceWatcher::QDBusServiceWatcher(QObject *parent = nullptr)

Constructs a watcher with the given parent that watches nothing yet.

QDBusServiceWatcher::QDBusServiceWatcher(const QString &service, const QDBusConnection &connection, WatchMode watchMode = WatchForOwnerChange, QObject *parent = nullptr)

Constructs a watcher with the given parent that watches service on connection for the changes watchMode selects.

[override] QDBusServiceWatcher::~QDBusServiceWatcher()

Destroys the watcher.

void QDBusServiceWatcher::addWatchedService(const QString &newService)

Adds newService to the names that are watched.

QDBusConnection QDBusServiceWatcher::connection() const

Returns the connection whose bus is watched.

bool QDBusServiceWatcher::removeWatchedService(const QString &service)

Stops watching service. Returns true if it was watched.

[signal] void QDBusServiceWatcher::serviceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)

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

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

This signal is emitted when the watched service gets an owner.

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

This signal is emitted when the watched service loses its owner.

void QDBusServiceWatcher::setConnection(const QDBusConnection &connection)

Watches the bus of connection instead.

void QDBusServiceWatcher::setWatchedServices(const QStringList &services)

Watches services instead of the names watched so far.

void QDBusServiceWatcher::setWatchMode(WatchMode mode)

Reports the changes that mode selects.

QStringList QDBusServiceWatcher::watchedServices() const

Returns the names that are watched.

WatchMode QDBusServiceWatcher::watchMode() const

Returns the changes that are reported.