6.0.0-rc4Source

QDBusAbstractInterface Class

The QDBusAbstractInterface class is the base class for all D-Bus interfaces in the Nt D-Bus binding, allowing access to remote interfaces. More…

Header#include <QDBusAbstractInterface>
CMaketarget_link_libraries(app PRIVATE Nt::DBus)
ModuleNt D-Bus C++ Classes
InheritsQObject
Inherited byQDBusConnectionInterface, QDBusInterface

List of all members, including inherited members

Public Functions

~QDBusAbstractInterface()
boolisValid() const
QDBusConnectionconnection() const
QStringservice() const
QStringpath() const
QStringinterface() const
QDBusErrorlastError() const
voidsetTimeout(int timeout)
inttimeout() const
voidsetInteractiveAuthorizationAllowed(bool enable)
boolisInteractiveAuthorizationAllowed() const
QVariantproperty(const char *name) const
boolsetProperty(const char *name, const QVariant &value)
QDBusMessagecall(const QString &method, Args &&...args)
QDBusMessagecall(QDBus::CallMode mode, const QString &method, Args &&...args)
QDBusPendingCallasyncCall(const QString &method, Args &&...args)
QDBusMessagecallWithArgumentList(QDBus::CallMode mode, const QString &method, const QList<QVariant> &args)
QDBusPendingCallasyncCallWithArgumentList(const QString &method, const QList<QVariant> &args)
boolcallWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *returnMethod, const char *errorMethod)
boolcallWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *slot)

Protected Functions

QDBusAbstractInterface(const QString &service, const QString &path, const char *interface, const QDBusConnection &connection, QObject *parent)
QVariantinternalPropGet(const char *propname) const
voidinternalPropSet(const char *propname, const QVariant &value)

Detailed Description

Subclass it to write a proxy class for one remote interface: methods call callWithArgumentList() or asyncCall(), and signals that the class declares are emitted when the remote object emits the D-Bus signal of the same name:

class ClockInterface : public QDBusAbstractInterface {
    Q_OBJECT
public:
    explicit ClockInterface(const QDBusConnection &connection, QObject *parent = nullptr)
        : QDBusAbstractInterface("org.example.Clock", "/clock", "org.example.Clock", connection, parent) {}

    QDBusPendingReply<QString> Now() { return asyncCall("Now"); }
    QDBusPendingReply<> SetAlarm(int seconds, const QString &message) {
        return asyncCall("SetAlarm", seconds, message);
    }

signals:
    void alarm(const QString &message); // emitted when the remote clock emits it
};

QDBusInterface is a ready-made subclass for interfaces known only at run time.

See also QDBusInterface and QDBusConnection.

Differences from Qt

property() and setProperty() hide those of QObject and read and write the remote properties; call them through a QDBusAbstractInterface pointer or reference. A subclass relays every signal of the remote interface that it declares, whether connected or not. There is no qdbusxml2cpp to generate subclasses.

Member Function Documentation

[protected] QDBusAbstractInterface::QDBusAbstractInterface(const QString &service, const QString &path, const char *interface, const QDBusConnection &connection, QObject *parent)

Constructs an interface to interface of the object at path in service, reached through connection, with the given parent.

[override] QDBusAbstractInterface::~QDBusAbstractInterface()

Destroys the interface.

template <typename... Args>QDBusPendingCall QDBusAbstractInterface::asyncCall(const QString &method, Args &&...args)

Calls method on the remote object with the arguments args and returns at once.

QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString &method, const QList<QVariant> &args)

Calls method with the arguments args and returns at once.

template <typename... Args>QDBusMessage QDBusAbstractInterface::call(const QString &method, Args &&...args)

Calls method on the remote object with the arguments args and blocks for the reply.

template <typename... Args>QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &method, Args &&...args)

This is an overloaded function.

Calls method on the remote object with the arguments args, waiting as mode says.

QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode, const QString &method, const QList<QVariant> &args)

Calls method with the arguments args and waits as mode says. Returns the reply, which is an error message if the call failed.

bool QDBusAbstractInterface::callWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *returnMethod, const char *errorMethod)

Calls method with the arguments args. When the reply arrives, returnMethod of receiver is called with it, or errorMethod with the error. Returns true if the call was sent.

See also QDBusConnection::callWithCallback().

bool QDBusAbstractInterface::callWithCallback(const QString &method, const QList<QVariant> &args, QObject *receiver, const char *slot)

This is an overloaded function.

Calls method with the arguments args and calls slot of receiver with the reply.

QDBusConnection QDBusAbstractInterface::connection() const

Returns the connection that the interface uses.

QString QDBusAbstractInterface::interface() const

Returns the name of the remote interface.

[protected] QVariant QDBusAbstractInterface::internalPropGet(const char *propname) const

Reads the remote property propname with org.freedesktop.DBus.Properties.Get. If this class declares the property, the value is converted to its type.

[protected] void QDBusAbstractInterface::internalPropSet(const char *propname, const QVariant &value)

Writes value to the remote property propname with org.freedesktop.DBus.Properties.Set.

bool QDBusAbstractInterface::isInteractiveAuthorizationAllowed() const

Returns true if the calls allow interactive authorization.

bool QDBusAbstractInterface::isValid() const

Returns true if the connection is open and the remote service exists.

QDBusError QDBusAbstractInterface::lastError() const

Returns the error of the last call that failed.

QString QDBusAbstractInterface::path() const

Returns the path of the remote object.

QVariant QDBusAbstractInterface::property(const char *name) const

Returns the value of the remote property name, or an invalid QVariant if it cannot be read; lastError() then says why. The property objectName is that of this QObject.

QString QDBusAbstractInterface::service() const

Returns the name of the remote service.

void QDBusAbstractInterface::setInteractiveAuthorizationAllowed(bool enable)

Sets whether the calls allow the remote side to ask the user for authorization to enable.

bool QDBusAbstractInterface::setProperty(const char *name, const QVariant &value)

Sets the remote property name to value. Returns true on success.

void QDBusAbstractInterface::setTimeout(int timeout)

Sets the timeout of the calls to timeout milliseconds; -1 selects the default.

int QDBusAbstractInterface::timeout() const

Returns the timeout of the calls in milliseconds, or -1 for the default.