QDBusContext Class ReferenceThe QDBusContext class allows slots to determine the D-Bus context of the calls. More... #include <QDBusContext> This class was introduced in Qt 4.3. Public Functions
Detailed DescriptionThe QDBusContext class allows slots to determine the D-Bus context of the calls. 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 QtDBus XML Compiler (qdbusxml2cpp). QDBusContext is used by subclassing it from the objects being exported using QDBusConnection::registerObject(). The following example illustrates the usage: class MyObject: public QObject, protected QDBusContext { Q_OBJECT QDBusConnection conn; QDBusMessage msg; ... protected slots: void process(); public slots: void methodWithError(); QString methodWithDelayedReply(); }; void MyObject::methodWithError() { sendErrorReply(QDBusError::NotSupported, "The method call 'methodWithError()' is not supported"); } QString MyObject::methodWithDelayedReply() { conn = connection(); msg = message(); setDelayedReply(true); QMetaObject::invokeMethod(this, "process", Qt::QueuedConnection); return 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 QObject::parent(). Member Function Documentation
|