QDBusServiceWatcher 类

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

头: #include <QDBusServiceWatcher>
qmake: QT += dbus
Since: Qt 4.6
继承: QObject

公共类型

flags WatchMode
enum WatchModeFlag { WatchForRegistration, WatchForUnregistration, WatchForOwnerChange }

特性

公共函数

QDBusServiceWatcher (QObject * parent = nullptr)
QDBusServiceWatcher (const QString & service , const QDBusConnection & connection , QDBusServiceWatcher::WatchMode watchMode = WatchForOwnerChange, QObject * parent = nullptr)
virtual ~QDBusServiceWatcher ()
void addWatchedService (const QString & newService )
QDBusConnection connection () const
bool removeWatchedService (const QString & service )
void setConnection (const QDBusConnection & connection )
void setWatchMode (QDBusServiceWatcher::WatchMode mode )
void setWatchedServices (const QStringList & services )
QDBusServiceWatcher::WatchMode watchMode () const
QStringList watchedServices () const

信号

void serviceOwnerChanged (const QString & serviceName , const QString & oldOwner , const QString & newOwner )
void serviceRegistered (const QString & serviceName )
void serviceUnregistered (const QString & serviceName )

静态公共成员

const QMetaObject staticMetaObject

额外继承成员

详细描述

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

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 () 和 serviceUnregistered () signals may not be emitted if that happens.

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

另请参阅 QDBusConnection .

成员类型文档编制

enum QDBusServiceWatcher:: WatchModeFlag
flags QDBusServiceWatcher:: WatchMode

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

常量 描述
QDBusServiceWatcher::WatchForRegistration 0x01 watch for service registration only, ignoring any signals related to other service ownership change.
QDBusServiceWatcher::WatchForUnregistration 0x02 watch for service unregistration only, ignoring any signals related to other service ownership change.
QDBusServiceWatcher::WatchForOwnerChange 0x03 watch for any kind of service ownership change.

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

特性文档编制

watchMode : WatchMode

The watchMode property holds the current watch mode for this QDBusServiceWatcher object. The default value for this property is QDBusServiceWatcher::WatchForOwnershipChange.

访问函数:

QDBusServiceWatcher::WatchMode watchMode () const
void setWatchMode (QDBusServiceWatcher::WatchMode mode )

watchedServices : QStringList

The servicesWatched property holds the list of services watched.

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

访问函数:

QStringList watchedServices () const
void setWatchedServices (const QStringList & services )

成员函数文档编制

QDBusServiceWatcher:: QDBusServiceWatcher ( QObject * parent = nullptr)

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

The parent 参数会被传递给 QObject to set the parent of this object.

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

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

The parent 参数会被传递给 QObject to set the parent of this object.

[虚拟] QDBusServiceWatcher:: ~QDBusServiceWatcher ()

销毁 QDBusServiceWatcher object and releases any resources associated with it.

void QDBusServiceWatcher:: addWatchedService (const QString & newService )

添加 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.

QDBusConnection QDBusServiceWatcher:: connection () const

返回 QDBusConnection that this object is attached to.

另请参阅 setConnection ().

bool QDBusServiceWatcher:: removeWatchedService (const QString & service )

移除 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.

此函数返回 true if any services were removed.

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

This signal is emitted whenever this object detects that there was a service ownership change relating to the serviceName service. The oldOwner parameter contains the old owner name and newOwner is the new owner. Both oldOwner and newOwner are unique connection names.

Note that this signal is also emitted whenever the serviceName service was registered or unregistered. If it was registered, oldOwner will contain an empty string, whereas if it was unregistered, newOwner will contain an empty string.

If you need only to find out if the service is registered or unregistered only, without being notified that the ownership changed, consider using the specific modes for those operations. This class is more efficient if you use the more specific modes.

另请参阅 serviceRegistered () 和 serviceUnregistered ().

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

This signal is emitted whenever this object detects that the service serviceName became available on the bus.

另请参阅 serviceUnregistered () 和 serviceOwnerChanged ().

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

This signal is emitted whenever this object detects that the service serviceName was unregistered from the bus and is no longer available.

另请参阅 serviceRegistered () 和 serviceOwnerChanged ().

void QDBusServiceWatcher:: setConnection (const QDBusConnection & connection )

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

注意, 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.

另请参阅 connection ().

void QDBusServiceWatcher:: setWatchedServices (const QStringList & services )

Sets the list of D-Bus services being watched to be services .

Note that setting the entire list means removing all previous rules for watching services and adding new ones. This is an expensive operation and should be avoided, if possible. Instead, use addWatchedService () 和 removeWatchedService () if you can to manipulate entries in the list.

注意: setter 函数对于特性 watchedServices .

另请参阅 watchedServices ().

QStringList QDBusServiceWatcher:: watchedServices () const

Returns the list of D-Bus services that are being watched.

注意: getter 函数对于特性 watchedServices .

另请参阅 setWatchedServices ().