QDBusServiceWatcher

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

Inheritance diagram of PySide6.QtDBus.QDBusServiceWatcher

Synopsis

Functions

Signals

Detailed Description

A QDBusServiceWatcher object can be used to notify the application about an ownership change of a service name on the bus. It has three watch modes:

  • Watching for service registration only.

  • Watching for service unregistration only.

  • Watching for any kind of service ownership change (the default mode).

Besides being created or deleted, services may change owners without a unregister/register operation happening. So the serviceRegistered() and serviceUnregistered() signals may not be emitted if that happens.

This class is more efficient than using the signal because it allows one to receive only the signals for which the class is interested in.

Ending a service name with the character ‘*’ will match all service names within the specified namespace.

For example “com.example.backend1*” will match

  • com.example.backend1

  • com.example.backend1.foo

  • com.example.backend1.foo.bar

Substrings in the same domain will not be matched, i.e “com.example.backend12”.

See also

QDBusConnection

class PySide6.QtDBus.QDBusServiceWatcher([parent=None])

PySide6.QtDBus.QDBusServiceWatcher(service, connection[, watchMode=QDBusServiceWatcher.WatchModeFlag.WatchForOwnerChange[, parent=None]])

Parameters

Creates a QDBusServiceWatcher object. Note that until you set a connection with setConnection() , this object will not emit any signals.

The parent parameter is passed to QObject to set the parent of this object.

Creates a QDBusServiceWatcher object and attaches it to the connection connection. Also, this function immediately starts watching for watchMode changes to service service.

The parent parameter is passed to QObject to set the parent of this object.

PySide6.QtDBus.QDBusServiceWatcher.WatchModeFlag

QDBusServiceWatcher supports three different watch modes, which are configured by this flag:

Constant

Description

QDBusServiceWatcher.WatchForRegistration

watch for service registration only, ignoring any signals related to other service ownership change.

QDBusServiceWatcher.WatchForUnregistration

watch for service unregistration only, ignoring any signals related to other service ownership change.

QDBusServiceWatcher.WatchForOwnerChange

watch for any kind of service ownership change.

PySide6.QtDBus.QDBusServiceWatcher.addWatchedService(newService)
Parameters

newService – str

Adds newService to the list of services to be watched by this object. This function is more efficient than setWatchedServices() and should be used whenever possible to add services.

Removes any existing binding of watchedServices .

PySide6.QtDBus.QDBusServiceWatcher.connection()
Return type

PySide6.QtDBus.QDBusConnection

Returns the QDBusConnection that this object is attached to.

See also

setConnection()

PySide6.QtDBus.QDBusServiceWatcher.removeWatchedService(service)
Parameters

service – str

Return type

bool

Removes the service from the list of services being watched by this object. Note that D-Bus notifications are asynchronous, so there may still be signals pending delivery about service. Those signals will still be emitted whenever the D-Bus messages are processed.

Removes any existing binding of watchedServices .

This function returns true if any services were removed.

PySide6.QtDBus.QDBusServiceWatcher.serviceOwnerChanged(service, oldOwner, newOwner)
Parameters
  • service – str

  • oldOwner – str

  • newOwner – str

PySide6.QtDBus.QDBusServiceWatcher.serviceRegistered(service)
Parameters

service – str

PySide6.QtDBus.QDBusServiceWatcher.serviceUnregistered(service)
Parameters

service – str

PySide6.QtDBus.QDBusServiceWatcher.setConnection(connection)
Parameters

connectionPySide6.QtDBus.QDBusConnection

Sets the D-Bus connection that this object is attached to be connection. All services watched will be transferred to this connection.

Note that QDBusConnection objects are reference counted: QDBusServiceWatcher will keep a reference for this connection while it exists. The connection is not closed until the reference count drops to zero, so this will ensure that any notifications are received while this QDBusServiceWatcher object exists.

See also

connection()

PySide6.QtDBus.QDBusServiceWatcher.setWatchMode(mode)
Parameters

modeWatchMode

This property holds the current watch mode for this QDBusServiceWatcher object..

The default value for this property is QDBusServiceWatcher::WatchForOwnershipChange.

PySide6.QtDBus.QDBusServiceWatcher.setWatchedServices(services)
Parameters

services – list of strings

This property holds the list of services watched..

Note

Modifying this list with setServicesWatched() is an expensive operation. If you can, prefer to change it by way of addWatchedService() and removeWatchedService() .

PySide6.QtDBus.QDBusServiceWatcher.watchMode()
Return type

WatchMode

This property holds the current watch mode for this QDBusServiceWatcher object..

The default value for this property is QDBusServiceWatcher::WatchForOwnershipChange.

PySide6.QtDBus.QDBusServiceWatcher.watchedServices()
Return type

list of strings

This property holds the list of services watched..

Note

Modifying this list with setServicesWatched() is an expensive operation. If you can, prefer to change it by way of addWatchedService() and removeWatchedService() .