PySide6.QtDBus.QDBusConnection¶
- class QDBusConnection¶
- The - QDBusConnectionclass represents a connection to the D-Bus bus daemon. More…- Synopsis¶- Methods¶- def - __init__()
- def - asyncCall()
- def - baseService()
- def - call()
- def - connect()
- def - disconnect()
- def - interface()
- def - isConnected()
- def - lastError()
- def - name()
- def - registerObject()
- def - send()
- def - swap()
 - Static functions¶- def - connectToBus()
- def - connectToPeer()
- def - localMachineId()
- def - sessionBus()
- def - systemBus()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- 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 connection.- The connection is then torn down using the - disconnectFromBus()function.- Once disconnected, calling - connectToBus()will not reestablish a connection, you must create a new- QDBusConnectioninstance.- As a convenience for the two most common connection types, the - sessionBus()and- 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.- class BusType¶
- Specifies the type of the bus connection. The valid bus types are: - Constant - Description - QDBusConnection.SessionBus - the session bus, associated with the running desktop session - QDBusConnection.SystemBus - the system bus, used to communicate with system-wide processes - QDBusConnection.ActivationBus - 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. 
 - class RegisterOption¶
- (inherits - enum.Flag) Specifies the options for registering objects with the connection. The possible values are:- Constant - Description - QDBusConnection.ExportAdaptors - export the contents of adaptors found in this object - QDBusConnection.ExportScriptableSlots - export this object’s scriptable slots - QDBusConnection.ExportScriptableSignals - export this object’s scriptable signals - QDBusConnection.ExportScriptableProperties - export this object’s scriptable properties - QDBusConnection.ExportScriptableInvokables - export this object’s scriptable invokables - QDBusConnection.ExportScriptableContents - shorthand form for ExportScriptableSlots | ExportScriptableSignals | ExportScriptableProperties - QDBusConnection.ExportNonScriptableSlots - export this object’s non-scriptable slots - QDBusConnection.ExportNonScriptableSignals - export this object’s non-scriptable signals - QDBusConnection.ExportNonScriptableProperties - export this object’s non-scriptable properties - QDBusConnection.ExportNonScriptableInvokables - export this object’s non-scriptable invokables - QDBusConnection.ExportNonScriptableContents - shorthand form for ExportNonScriptableSlots | ExportNonScriptableSignals | ExportNonScriptableProperties - QDBusConnection.ExportAllSlots - export all of this object’s slots - QDBusConnection.ExportAllSignals - export all of this object’s signals - QDBusConnection.ExportAllProperties - export all of this object’s properties - QDBusConnection.ExportAllInvokables - export all of this object’s invokables - QDBusConnection.ExportAllContents - export all of this object’s contents - QDBusConnection.ExportChildObjects - export this object’s child objects 
 - class UnregisterMode¶
- The mode for unregistering an object path: - Constant - Description - QDBusConnection.UnregisterNode - unregister this node only: do not unregister child objects - QDBusConnection.UnregisterTree - unregister this node and all its sub-tree - Note, however, if this object was registered with the - ExportChildObjectsoption, UnregisterNode will unregister the child objects too.
 - class VirtualObjectRegisterOption¶
 - class ConnectionCapability¶
- (inherits - enum.Flag) This enum describes the available capabilities for a D-Bus connection.- Constant - Description - QDBusConnection.UnixFileDescriptorPassing - enables passing of Unix file descriptors to other processes (see - QDBusUnixFileDescriptor)- See also 
 - __init__(other)¶
- Parameters:
- other – - QDBusConnection
 
 - Creates a copy of the - otherconnection.- __init__(name)
- Parameters:
- name – str 
 
 - Creates a - QDBusConnectionobject attached to the connection with name- name.- This does not open the connection. You have to call - connectToBus()to open it.- asyncCall(message[, timeout=-1])¶
- Parameters:
- message – - QDBusMessage
- timeout – int 
 
- Return type:
 
 - Sends the - messageover this connection and returns immediately. This function is suitable for method calls only. It returns an object of type- QDBusPendingCallwhich can be used to track the status of the reply.- If no reply is received within - timeoutmilliseconds, an automatic error will be delivered indicating the expiration of the call. The default- timeoutis -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().- See the - asyncCall()function for a more friendly way of placing calls.- Note - Method calls to objects registered by the application itself are never asynchronous due to implementation limitations. - baseService()¶
- Return type:
- str 
 
 - Returns the unique connection name for this connection, if this - QDBusConnectionobject is connected, or an empty QString otherwise.- 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. - call(message[, mode=QDBus.Block[, timeout=-1]])¶
- Parameters:
- message – - QDBusMessage
- mode – - CallMode
- timeout – int 
 
- Return type:
 
 - Sends the - messageover this connection and blocks, waiting for a reply, for at most- timeoutmilliseconds. This function is suitable for method calls only. It returns the reply message as its return value, which will be either of type- ReplyMessageor- ErrorMessage.- If no reply is received within - timeoutmilliseconds, an automatic error will be delivered indicating the expiration of the call. The default- timeoutis -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds).- See the - call()function for a more friendly way of placing calls.- Warning - If - modeis- 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().- callWithCallback(message, receiver, slot[, timeout=-1])¶
- Parameters:
- message – - QDBusMessage
- receiver – - QObject
- slot – str 
- timeout – int 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Sends the - messageover this connection and returns immediately. When the reply is received, the method- returnMethodis called in the- receiverobject.- 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 - trueif the message was sent, or false if the message could not be sent.- callWithCallback(message, receiver, returnMethod, errorMethod[, timeout=-1])
- Parameters:
- message – - QDBusMessage
- receiver – - QObject
- returnMethod – str 
- errorMethod – str 
- timeout – int 
 
- Return type:
- bool 
 
 - Sends the - messageover this connection and returns immediately. When the reply is received, the method- returnMethodis called in the- receiverobject. If an error occurs, the method- errorMethodwill be called instead.- If no reply is received within - timeoutmilliseconds, an automatic error will be delivered indicating the expiration of the call. The default- timeoutis -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 - trueif the message was sent, or false if the message could not be sent.- connect(service, path, interface, name, receiver, slot)¶
- Parameters:
- service – str 
- path – str 
- interface – str 
- name – str 
- receiver – - QObject
- slot – str 
 
- Return type:
- bool 
 
 - Connects the signal specified by the - service,- path,- interfaceand- nameparameters to the slot- slotin object- receiver. The arguments- serviceand- pathcan be empty, denoting a connection to any signal of the (- interface,- name) pair, from any remote application.- Returns - trueif the connection was successful.- Warning - 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. - connect(service, path, interface, name, signature, receiver, slot)
- Parameters:
- service – str 
- path – str 
- interface – str 
- name – str 
- signature – str 
- receiver – - QObject
- slot – str 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Connects the signal to the slot - slotin object- receiver. Unlike the previous- connect()overload, this function allows one to specify the parameter signature to be connected using the- signaturevariable. The function will then verify that this signature can be delivered to the slot specified by- slotand return false otherwise.- Returns - trueif the connection was successful.- Note - 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. - connect(service, path, interface, name, argumentMatch, signature, receiver, slot)
- Parameters:
- service – str 
- path – str 
- interface – str 
- name – str 
- argumentMatch – list of strings 
- signature – str 
- receiver – - QObject
- slot – str 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Connects the signal to the slot - slotin object- receiver. Unlike the previous- connect()overload, this function allows one to specify the parameter signature to be connected using the- signaturevariable. The function will then verify that this signature can be delivered to the slot specified by- slotand return false otherwise.- The - argumentMatchparameter 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 - trueif the connection was successful.- Note - 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. - Opens a connection of type - typeto one of the known buses and associate with it the connection name- name. Returns a- QDBusConnectionobject associated with that connection.- static connectToBus(address, name)
- Parameters:
- address – str 
- name – str 
 
- Return type:
 
 - Opens a connection to a private bus on address - addressand associate with it the connection name- name. Returns a- QDBusConnectionobject associated with that connection.- static connectToPeer(address, name)¶
- Parameters:
- address – str 
- name – str 
 
- Return type:
 
 - Opens a peer-to-peer connection on address - addressand associate with it the connection name- name. Returns a- QDBusConnectionobject associated with that connection.- connectionCapabilities()¶
- Return type:
- Combination of - ConnectionCapability
 
 - Returns the capabilities of this connection as negotiated with the bus server or peer. If this - QDBusConnectionis not connected, this function returns no capabilities.- disconnect(service, path, interface, name, receiver, slot)¶
- Parameters:
- service – str 
- path – str 
- interface – str 
- name – str 
- receiver – - QObject
- slot – str 
 
- Return type:
- bool 
 
 - Disconnects the signal specified by the - service,- path,- interfaceand- nameparameters from the slot- slotin object- receiver. The arguments must be the same as passed to the- connect()function.- Returns - trueif the disconnection was successful.- disconnect(service, path, interface, name, signature, receiver, slot)
- Parameters:
- service – str 
- path – str 
- interface – str 
- name – str 
- signature – str 
- receiver – - QObject
- slot – str 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Disconnects the signal specified by the - service,- path,- interface,- name, and- signatureparameters from the slot- slotin object- receiver. The arguments must be the same as passed to the- connect()function.- Returns - trueif the disconnection was successful.- disconnect(service, path, interface, name, argumentMatch, signature, receiver, slot)
- Parameters:
- service – str 
- path – str 
- interface – str 
- name – str 
- argumentMatch – list of strings 
- signature – str 
- receiver – - QObject
- slot – str 
 
- Return type:
- bool 
 
 - This is an overloaded function. - Disconnects the signal specified by the - service,- path,- interface,- name,- argumentMatch, and- signatureparameters from the slot- slotin object- receiver. The arguments must be the same as passed to the- connect()function.- Returns - trueif the disconnection was successful.- static disconnectFromBus(name)¶
- Parameters:
- name – str 
 
 - Closes the bus connection of name - name.- Note that if there are still - QDBusConnectionobjects 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- QDBusConnectionconstructor.- static disconnectFromPeer(name)¶
- Parameters:
- name – str 
 
 - Closes the peer connection of name - name.- Note that if there are still - QDBusConnectionobjects 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- QDBusConnectionconstructor.- interface()¶
- Return type:
 
 - Returns a - QDBusConnectionInterfaceobject that represents the D-Bus server interface on this connection.- internalPointer()¶
- Return type:
- void
 
 - isConnected()¶
- Return type:
- bool 
 
 - Returns - trueif this- QDBusConnectionobject is connected.- lastError()¶
- Return type:
 
 - Returns the last error that happened in this connection. - This function is provided for low-level code. If you’re using - call(), error codes are reported by its return value.- See also - static localMachineId()¶
- Return type:
 
 - 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. - name()¶
- Return type:
- str 
 
 - 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.- See also - Return the object that was registered with the - registerObject()at the object path given by- path.- registerObject(path, object[, options=QDBusConnection.RegisterOption.ExportAdaptors])¶
- Parameters:
- path – str 
- object – - QObject
- options – Combination of - RegisterOption
 
- Return type:
- bool 
 
 - Registers the object - objectat path- pathand returns- trueif the registration was successful. The- optionsparameter specifies how much of the object- objectwill be 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()to unregister it first.- The - ExportChildObjectsflag exports child objects on D-Bus based on the path of the registered objects and the QObject::objectName of the child. Therefore, it is important for the child object to have an object name.- You cannot register an object as a child object of an object that was registered with - ExportChildObjects.- registerObject(path, interface, object[, options=QDBusConnection.RegisterOption.ExportAdaptors])
- Parameters:
- path – str 
- interface – str 
- object – - QObject
- options – Combination of - RegisterOption
 
- Return type:
- bool 
 
 - This is an overloaded function. - Registers the object - objectat path- pathwith interface name- interfaceand returns- trueif the registration was successful. The- optionsparameter specifies how much of the object- objectwill be 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()to unregister it first.- The - ExportChildObjectsflag exports child objects on D-Bus based on the path of the registered objects and the QObject::objectName of the child. Therefore, it is important for the child object to have an object name.- You cannot register an object as a child object of an object that was registered with - ExportChildObjects.- registerService(serviceName)¶
- Parameters:
- serviceName – str 
- Return type:
- bool 
 
 - Attempts to register the - serviceNameon the D-Bus server and returns- trueif the registration succeeded. The registration will fail if the name is already registered by another application.- See also - registerVirtualObject(path, object[, options=QDBusConnection.VirtualObjectRegisterOption.SingleNode])¶
- Parameters:
- path – str 
- object – - QDBusVirtualObject
- options – - VirtualObjectRegisterOption
 
- Return type:
- bool 
 
 - send(message)¶
- Parameters:
- message – - QDBusMessage
- Return type:
- bool 
 
 - Sends the - messageover 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 - trueif the message was queued successfully, false otherwise.- static sessionBus()¶
- Return type:
 
 - Returns a - QDBusConnectionobject 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.- swap(other)¶
- Parameters:
- other – - QDBusConnection
 
 - Swaps this connection with - other. This operation is very fast and never fails.- static systemBus()¶
- Return type:
 
 - Returns a - QDBusConnectionobject 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.- unregisterObject(path[, mode=QDBusConnection.UnregisterMode.UnregisterNode])¶
- Parameters:
- path – str 
- mode – - UnregisterMode
 
 
 - Unregisters an object that was registered with the - registerObject()at the object path given by- pathand, if- modeis- UnregisterTree, all of its sub-objects too.- Note that you cannot unregister objects that were not registered with - registerObject().- unregisterService(serviceName)¶
- Parameters:
- serviceName – str 
- Return type:
- bool 
 
 - Unregisters the service - serviceNamethat was previously registered with- registerService()and returns- trueif it succeeded.- See also