The QDBusConnection class represents a connection to the D-Bus bus daemon. 更多...
The QDBusConnection class represents a connection to the D-Bus bus daemon.
This class is the initial point in a D-Bus session. Using it, you can get access to remote objects, interfaces; connect remote signals to your object's slots; register objects, etc.
D-Bus connections are created using the connectToBus () function, which opens a connection to the server daemon and does the initial handshaking, associating that connection with a name. Further attempts to connect using the same name will return the same 连接。
The connection is then torn down using the disconnectFromBus () 函数。
Once disconnected, calling connectToBus () will not reestablish a connection, you must create a new QDBusConnection 实例。
As a convenience for the two most common connection types, the sessionBus () 和 systemBus () functions return open connections to the session server daemon and the system server daemon, respectively. Those connections are opened when first used and are closed when the QCoreApplication destructor is run.
D-Bus also supports peer-to-peer connections, without the need for a bus server daemon. Using this facility, two applications can talk to each other and exchange messages. This can be achieved by passing an address to connectToBus () function, which was opened by another D-Bus application using QDBusServer.
Specifies the type of the bus connection. The valid bus types 是:
| 常量 | 值 | 描述 |
|---|---|---|
| QDBusConnection.SessionBus | 0 | the session bus, associated with the running desktop session |
| QDBusConnection.SystemBus | 1 | the system bus, used to communicate with system-wide processes |
| QDBusConnection.ActivationBus | 2 | the activation bus, the "alias" for the bus that started the service |
On the Session Bus, one can find other applications by the same user that are sharing the same desktop session (hence the name). On the System Bus, however, processes shared for the whole system are usually found.
This enum describes the available capabilities for a D-Bus 连接。
| 常量 | 值 | 描述 |
|---|---|---|
| QDBusConnection.UnixFileDescriptorPassing | 0x0001 | enables passing of Unix file descriptors to other processes (see QDBusUnixFileDescriptor ) |
该枚举在 Qt 4.8 引入或被修改。
The ConnectionCapabilities type is a typedef for QFlags <ConnectionCapability>. It stores an OR combination of ConnectionCapability values.
另请参阅 connectionCapabilities ().
Specifies the options for registering objects with the connection. The possible values are:
| 常量 | 值 | 描述 |
|---|---|---|
| QDBusConnection.ExportAdaptors | 0x01 | export the contents of adaptors found in this object |
| QDBusConnection.ExportScriptableSlots | 0x10 | export this object's scriptable slots |
| QDBusConnection.ExportScriptableSignals | 0x20 | export this object's scriptable signals |
| QDBusConnection.ExportScriptableProperties | 0x40 | export this object's scriptable properties |
| QDBusConnection.ExportScriptableInvokables | 0x80 | export this object's scriptable invokables |
| QDBusConnection.ExportScriptableContents | 0xf0 | shorthand form for ExportScriptableSlots | ExportScriptableSignals | ExportScriptableProperties |
| QDBusConnection.ExportNonScriptableSlots | 0x100 | export this object's non-scriptable slots |
| QDBusConnection.ExportNonScriptableSignals | 0x200 | export this object's non-scriptable signals |
| QDBusConnection.ExportNonScriptableProperties | 0x400 | export this object's non-scriptable properties |
| QDBusConnection.ExportNonScriptableInvokables | 0x800 | export this object's non-scriptable invokables |
| QDBusConnection.ExportNonScriptableContents | 0xf00 | shorthand form for ExportNonScriptableSlots | ExportNonScriptableSignals | ExportNonScriptableProperties |
| QDBusConnection.ExportAllSlots | ExportScriptableSlots | ExportNonScriptableSlots | export all of this object's slots |
| QDBusConnection.ExportAllSignals | ExportScriptableSignals | ExportNonScriptableSignals | export all of this object's signals |
| QDBusConnection.ExportAllProperties | ExportScriptableProperties | ExportNonScriptableProperties | export all of this object's properties |
| QDBusConnection.ExportAllInvokables | ExportScriptableInvokables | ExportNonScriptableInvokables | export all of this object's invokables |
| QDBusConnection.ExportAllContents | ExportScriptableContents | ExportNonScriptableContents | export all of this object's contents |
| QDBusConnection.ExportChildObjects | 0x1000 | export this object's child objects |
The RegisterOptions type is a typedef for QFlags <RegisterOption>. It stores an OR combination of RegisterOption values.
另请参阅 registerObject (), QDBusAbstractAdaptor ,和 Using adaptors .
The mode for unregistering an object path:
| 常量 | 值 | 描述 |
|---|---|---|
| QDBusConnection.UnregisterNode | 0 | unregister this node only: do not unregister 子级对象 |
| QDBusConnection.UnregisterTree | 1 | unregister this node and all its sub-tree |
Note, however, if this object was registered with the ExportChildObjects option, UnregisterNode will unregister the child objects too.
创建 QDBusConnection object attached to the connection with name name .
This does not open the connection. You have to call connectToBus () to open it.
创建副本为 other 连接。
发送 message over this connection and returns immediately. This function is suitable for method calls only. It returns an object of type QDBusPendingCall which can be used to track the status of the reply.
If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds). This timeout is also the upper limit for waiting in QDBusPendingCall.waitForFinished().
见 QDBusInterface.asyncCall () function for a more friendly way of placing calls.
该函数在 Qt 4.5 引入。
Returns the unique connection name for this connection, if this QDBusConnection object is connected, or an empty QString 否则。
A Unique Connection Name is a string in the form ":x.xxx" (where x are decimal digits) that is assigned by the D-Bus server daemon upon connection. It uniquely identifies this client in the bus.
This function returns an empty QString for peer-to-peer connections.
发送 message over this connection and blocks, waiting for a reply, for at most timeout milliseconds. This function is suitable for method calls only. It returns the reply message as its return value, which will be either of type QDBusMessage.ReplyMessage or QDBusMessage.ErrorMessage .
If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds).
见 QDBusInterface.call () function for a more friendly way of placing calls.
警告: 若 mode is QDBus.BlockWithGui , this function will reenter the Qt event loop in order to wait for the reply. During the wait, it may deliver signals and other method calls to your application. Therefore, it must be prepared to handle a reentrancy whenever a call is placed with call().
发送 message over this connection and returns immediately. When the reply is received, the method returnMethod is called in the receiver object. If an error occurs, the method errorMethod will be called 代替。
If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds).
This function is suitable for method calls only. It is guaranteed that the slot will be called exactly once with the reply, as long as the parameter types match and no error occurs.
Returns true if the message was sent, or false if the message could not be sent.
此函数被弃用。
这是重载函数。
发送 message over this connection and returns immediately. When the reply is received, the method returnMethod is called in the receiver 对象。
This function is suitable for method calls only. It is guaranteed that the slot will be called exactly once with the reply, as long as the parameter types match and no error occurs.
This function is dangerous because it cannot report errors, including the expiration of the timeout.
Returns true if the message was sent, or false if the message could not be sent.
Connects the signal specified by the service , path , interface and name parameters to the slot slot in object receiver . The arguments service and path can be empty, denoting a connection to any signal of the ( interface , name ) pair, from any remote application.
Returns true if the connection was successful.
警告: The signal will only be delivered to the slot if the parameters match. This verification can be done only when the signal is received, not at connection time.
这是重载函数。
Connects the signal to the slot slot in object receiver . Unlike the previous connect () overload, this function allows one to specify the parameter signature to be connected using the signature variable. The function will then verify that this signature can be delivered to the slot 指定通过 slot and return false otherwise.
Returns true if the connection was successful.
注意: This function verifies that the signal signature matches the slot's parameters, but it does not verify that the actual signal exists with the given signature in the remote service.
这是重载函数。
Connects the signal to the slot slot in object receiver . Unlike the previous connect () overload, this function allows one to specify the parameter signature to be connected using the signature variable. The function will then verify that this signature can be delivered to the slot 指定通过 slot and return false otherwise.
argumentMatch parameter lists the string parameters to be matched, in sequential order. Note that, to match an empty string, you need to pass a QString that is empty but not null (i.e., QString ("")). A null QString skips matching at that position.
Returns true if the connection was successful.
注意: This function verifies that the signal signature matches the slot's parameters, but it does not verify that the actual signal exists with the given signature in the remote service.
该函数在 Qt 4.6 引入。
Returns the capabilities of this connection as negotiated with the bus server or peer. If this QDBusConnection is not connected, this function returns no capabilities.
该函数在 Qt 4.8 引入。
Opens a connection of type type to one of the known busses and associate with it the connection name name . 返回 QDBusConnection object associated with that connection.
Opens a connection to a private bus on address address and associate with it the connection name name 。返回 QDBusConnection object associated with that connection.
Opens a peer-to-peer connection on address address and associate with it the connection name name 。返回 QDBusConnection object associated with that connection.
该函数在 Qt 4.8 引入。
Disconnects the signal specified by the service , path , interface and name parameters from the slot slot in object receiver . The arguments must be the same as passed to the connect () 函数。
Returns true if the disconnection was successful.
这是重载函数。
Disconnects the signal specified by the service , path , interface , name ,和 signature parameters from the slot slot in object receiver 。 arguments must be the same as passed to the connect () 函数。
Returns true if the disconnection was successful.
这是重载函数。
Disconnects the signal specified by the service , path , interface , name , argumentMatch , and signature parameters from the slot slot in object receiver . The arguments must be the same as passed to the connect () 函数。
Returns true if the disconnection was successful.
该函数在 Qt 4.6 引入。
Closes the bus connection of name name .
Note that if there are still QDBusConnection objects associated with the same connection, the connection will not be closed until all references are dropped. However, no further references can be created using the QDBusConnection 构造函数。
Closes the peer connection of name name .
Note that if there are still QDBusConnection objects associated with the same connection, the connection will not be closed until all references are dropped. However, no further references can be created using the QDBusConnection 构造函数。
该函数在 Qt 4.8 引入。
返回 QDBusConnectionInterface object that represents the D-Bus server interface on this connection.
返回 true,若此 QDBusConnection 对象被连接。
Returns the last error that happened in this connection.
This function is provided for low-level code. If you're using QDBusInterface.call (), error codes are reported by its return value.
另请参阅 QDBusInterface and QDBusMessage .
Returns the local machine ID as known to the D-Bus system. Each node or host that runs D-Bus has a unique identifier that can be used to distinguish it from other hosts if they are sharing resources like the filesystem.
Note that the local machine ID is not guaranteed to be persistent across boots of the system, so this identifier should not be stored in persistent storage (like the filesystem). It is guaranteed to remain constant only during the lifetime of this boot session.
该函数在 Qt 4.8 引入。
Returns the connection name for this connection, as given as the name parameter to connectToBus ().
The connection name can be used to uniquely identify actual underlying connections to buses. Copies made from a single connection will always implicitly share the underlying connection, and hence will have the same connection name.
Inversely, two connections having different connection names will always either be connected to different buses, or have a different unique name (as returned by baseService ()) on that bus.
该函数在 Qt 4.5 引入。
另请参阅 connectToBus () 和 disconnectFromBus ().
Return the object that was registered with the registerObject () at the object path given by path .
Registers the object object at path path and returns true if the registration was successful. The options parameter specifies how much of the object object 将是 exposed through D-Bus.
This function does not replace existing objects: if there is already an object registered at path path , this function will return false. Use unregisterObject () 到 unregister it first.
You cannot register an object as a child object of an object that was registered with QDBusConnection.ExportChildObjects .
Attempts to register the serviceName on the D-Bus server and returns true if the registration succeeded. The registration will fail if the name is already registered by another 应用程序。
另请参阅 unregisterService () and QDBusConnectionInterface.registerService ().
发送 message over this connection, without waiting for a reply. This is suitable for errors, signals, and return values as well as calls whose return values are not necessary.
Returns true if the message was queued successfully, false 否则。
Returns the connection that sent the signal, if called in a slot activated by QDBus ;否则它返回 0.
注意: Please avoid this function. This function is not thread-safe, so if there's any other thread delivering a D-Bus call, this function may return the wrong connection. In new code, please use QDBusContext.connection () (see that class for a description on how to use it).
警告: 此函数不 可重入 .
返回 QDBusConnection object opened with the session bus. The object reference returned by this function is valid until the application terminates, at which point the connection will be closed and the object deleted.
返回 QDBusConnection object opened with the system bus. The object reference returned by this function is valid until the QCoreApplication 's destructor is run, when the connection will be closed and the object, deleted.
Unregisters an object that was registered with the registerObject () at the object path given by path and, if mode is QDBusConnection.UnregisterTree , all of its sub-objects too.
Note that you cannot unregister objects that were not registered with registerObject ().
Unregisters the service serviceName that was previously registered with registerService () 和 returns true if it succeeded.
另请参阅 registerService () 和 QDBusConnectionInterface.unregisterService ().