QDBusContext¶
The QDBusContext
class allows slots to determine the D-Bus context of the calls. More…
Synopsis¶
Functions¶
def
calledFromDBus
()def
connection
()def
isDelayedReply
()def
message
()def
sendErrorReply
(name[, msg=””])def
sendErrorReply
(type[, msg=””])def
setDelayedReply
(enable)
Detailed Description¶
When a slot is called in an object due to a signal delivery or due to a remote method call, it is sometimes necessary to know the context in which that happened. In particular, if the slot determines that it wants to send the reply at a later opportunity or if it wants to reply with an error, the context is needed.
The QDBusContext
class is an alternative to accessing the context that doesn’t involve modifying the code generated by the Qt D-Bus XML compiler (qdbusxml2cpp) .
QDBusContext
is used by subclassing it from the objects being exported using registerObject()
. The following example illustrates the usage:
class MyObject(QObject, QDBusContext = protected() Q_OBJECT conn = QDBusConnection() msg = QDBusMessage() #... slots: = protected() def process(): slots: = public() def methodWithError(): methodWithDelayedReply = QString() def methodWithError(self): sendErrorReply(QDBusError.NotSupported, "The method call 'methodWithError()' is not supported") def methodWithDelayedReply(self): conn = connection() msg = message() setDelayedReply(True) QMetaObject.invokeMethod(self, "process", Qt.QueuedConnection) def QString():
The example illustrates the two typical uses, that of sending error replies and that of delayed replies.
Note: do not subclass QDBusContext
and QDBusAbstractAdaptor
at the same time. QDBusContext
should appear in the real object, not the adaptor. If it’s necessary from the adaptor code to determine the context, use a public inheritance and access the functions via parent()
.
- class PySide6.QtDBus.QDBusContext¶
PySide6.QtDBus.QDBusContext(QDBusContext)
- Parameters
QDBusContext –
PySide6.QtDBus.QDBusContext
Constructs an empty QDBusContext
.
- PySide6.QtDBus.QDBusContext.calledFromDBus()¶
- Return type
bool
Returns true
if we are processing a D-Bus call. If this function returns true
, the rest of the functions in this class are available.
Accessing those functions when this function returns false
is undefined and may lead to crashes.
- PySide6.QtDBus.QDBusContext.connection()¶
- Return type
Returns the connection from which this call was received.
- PySide6.QtDBus.QDBusContext.isDelayedReply()¶
- Return type
bool
Returns true
if this call will have a delayed reply.
See also
- PySide6.QtDBus.QDBusContext.message()¶
- Return type
Returns the message that generated this call.
This is an overloaded function.
Sends an error type
as a reply to the caller. The optional msg
parameter is a human-readable text explaining the failure.
If an error is sent, the return value and any output parameters from the called slot will be ignored by Qt D-Bus.
- PySide6.QtDBus.QDBusContext.sendErrorReply(name[, msg=""])
- Parameters
name – str
msg – str
Sends an error name
as a reply to the caller. The optional msg
parameter is a human-readable text explaining the failure.
If an error is sent, the return value and any output parameters from the called slot will be ignored by Qt D-Bus.
- PySide6.QtDBus.QDBusContext.setDelayedReply(enable)¶
- Parameters
enable – bool
Sets whether this call will have a delayed reply or not.
If enable
is false, Qt D-Bus will automatically generate a reply back to the caller, if needed, as soon as the called slot returns.
If enable
is true, Qt D-Bus will not generate automatic replies. It will also ignore the return value from the slot and any output parameters. Instead, the called object is responsible for storing the incoming message and send a reply or error at a later time.
Failing to send a reply will result in an automatic timeout error being generated by D-Bus.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.