QDBusServiceWatcher Class
The QDBusServiceWatcher class allows the user to watch for a bus service change. More…
| Header | #include <QDBusServiceWatcher> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::DBus) |
| Module | Nt D-Bus C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Types
| enum | WatchModeFlag |
| typedef | WatchMode |
Public Functions
| QDBusServiceWatcher(QObject *parent = nullptr) | |
| QDBusServiceWatcher(const QString &service, const QDBusConnection &connection, WatchMode watchMode = WatchForOwnerChange, QObject *parent = nullptr) | |
| ~QDBusServiceWatcher() | |
| QStringList | watchedServices() const |
| void | setWatchedServices(const QStringList &services) |
| void | addWatchedService(const QString &newService) |
| bool | removeWatchedService(const QString &service) |
| WatchMode | watchMode() const |
| void | setWatchMode(WatchMode mode) |
| QDBusConnection | connection() const |
| void | setConnection(const QDBusConnection &connection) |
Signals
| void | serviceRegistered(const QString &service) |
| void | serviceUnregistered(const QString &service) |
| void | serviceOwnerChanged(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
| Constant | Description |
|---|---|
QDBusServiceWatcher::WatchForRegistration | Report names that get an owner. |
QDBusServiceWatcher::WatchForUnregistration | Report names that lose their owner. |
QDBusServiceWatcher::WatchForOwnerChange | Report every change of owner. |
Member Function Documentation
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.
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.
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.
void QDBusServiceWatcher::serviceRegistered(const QString &service)
This signal is emitted when the watched service gets an owner.
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.