QDBusContext Class
The QDBusContext class allows slots to determine the D-Bus context of the calls. More…
| Header | #include <QDBusContext> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::DBus) |
| Module | Nt D-Bus C++ Classes |
List of all members, including inherited members
Public Functions
| QDBusContext() | |
| virtual | ~QDBusContext() |
| bool | calledFromDBus() const |
| QDBusConnection | connection() const |
| const QDBusMessage & | message() const |
| bool | isDelayedReply() const |
| void | setDelayedReply(bool enable) const |
| void | sendErrorReply(const QString &name, const QString &message = QString()) const |
| void | sendErrorReply(QDBusError::ErrorType type, const QString &message = QString()) const |
Detailed Description
Inherit QDBusContext in an exported object or adaptor, next to QObject. While a slot runs because of a D-Bus call, message() is the call and connection() the connection it came on. A slot can then reply later, or with an error:
class Store : public QObject, protected QDBusContext {
Q_OBJECT
public slots:
QString Get(const QString &key) {
if (!m_values.contains(key))
sendErrorReply(QDBusError::InvalidArgs, "no such key");
return m_values.value(key);
}
};
See also QDBusConnection::registerObject().
Differences from Qt
The destructor is virtual, and QDBusContext cannot be copied. The context is also set on the object that owns an adaptor while the adaptor's slot runs.
Member Function Documentation
QDBusContext::QDBusContext()
Constructs a context, which is empty until a D-Bus call arrives.
QDBusContext::~QDBusContext()
Destroys the context.
bool QDBusContext::calledFromDBus() const
Returns true if the slot that is running was called over D-Bus.
QDBusConnection QDBusContext::connection() const
Returns the connection on which the current call arrived. Valid only while calledFromDBus() is true.
bool QDBusContext::isDelayedReply() const
Returns true if the reply to the current call will be sent later.
const QDBusMessage & QDBusContext::message() const
Returns the message of the current call. Valid only while calledFromDBus() is true.
void QDBusContext::sendErrorReply(const QString &name, const QString &message = QString()) const
Sends the error name with the text message as the reply to the current call. The slot's return value is ignored.
void QDBusContext::sendErrorReply(QDBusError::ErrorType type, const QString &message = QString()) const
This is an overloaded function.
Sends an error of the type type with the text message as the reply.
void QDBusContext::setDelayedReply(bool enable) const
Sets whether the reply to the current call is sent later to enable. The slot's return value is then ignored; keep message() and send the reply with connection().send(message().createReply(...)).