| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#include <QString> |
| 5 |
#include <QDBusConnection> |
| 6 |
#include <QDBusArgument> |
| 7 |
#include <QDBusMetaType> |
| 8 |
#include <QDBusMessage> |
| 9 |
#include <QDBusContext> |
| 10 |
|
| 11 |
//! [0] |
| 12 |
class MyObject: public QObject, |
| 13 |
protected QDBusContext |
| 14 |
{ |
| 15 |
Q_OBJECT |
| 16 |
|
| 17 |
QDBusConnection conn; |
| 18 |
QDBusMessage msg; |
| 19 |
|
| 20 |
//... |
| 21 |
|
| 22 |
protected slots: |
| 23 |
void process(); |
| 24 |
public slots: |
| 25 |
void methodWithError(); |
| 26 |
QString methodWithDelayedReply(); |
| 27 |
}; |
| 28 |
|
| 29 |
void MyObject::methodWithError() |
| 30 |
{ |
| 31 |
sendErrorReply(QDBusError::NotSupported, |
| 32 |
"The method call 'methodWithError()' is not supported"); |
| 33 |
} |
| 34 |
|
| 35 |
QString MyObject::methodWithDelayedReply() |
| 36 |
{ |
| 37 |
conn = connection(); |
| 38 |
msg = message(); |
| 39 |
setDelayedReply(true); |
| 40 |
QMetaObject::invokeMethod(this, &MyObject::process, Qt::QueuedConnection); |
| 41 |
return QString(); |
| 42 |
} |
| 43 |
//! [0] |