QDBusServer Class
The QDBusServer class provides peer-to-peer communication between processes on the same computer. More…
| Header | #include <QDBusServer> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::DBus) |
| Module | Nt D-Bus C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Functions
| QDBusServer(const QString &address, QObject *parent = nullptr) | |
| QDBusServer(QObject *parent = nullptr) | |
| ~QDBusServer() | |
| bool | isConnected() const |
| QDBusError | lastError() const |
| QString | address() const |
| void | setAnonymousAuthenticationAllowed(bool value) |
Signals
| void | newConnection(const QDBusConnection &connection) |
Detailed Description
A server listens on an address and hands each client that connects to it as a QDBusConnection, without a bus in between:
QDBusServer server;
QObject::connect(&server, &QDBusServer::newConnection, [&](const QDBusConnection &peer) {
connections.append(peer);
connections.last().registerObject("/clock", &clock, QDBusConnection::ExportAllSlots);
});
// A client calls QDBusConnection::connectToPeer(server.address(), "clock").
Clients authenticate with EXTERNAL and must run as the same user as the server, unless setAnonymousAuthenticationAllowed() lets anyone in.
See also QDBusConnection::connectToPeer().
Differences from Qt
Only unix: addresses are supported; tmpdir and dir create a socket file there. A connection that the server accepted is closed when the last QDBusConnection that refers to it is destroyed, so keep a copy for as long as it is used.
Member Function Documentation
QDBusServer::QDBusServer(const QString &address, QObject *parent = nullptr)
Constructs a server that listens on address, such as unix:path=/tmp/app.sock, with the given parent.
QDBusServer::QDBusServer(QObject *parent = nullptr)
Constructs a server with the given parent that listens on a new socket in the directory for temporary files.
QDBusServer::~QDBusServer()
Destroys the server and stops listening. The connections it accepted stay open.
QString QDBusServer::address() const
Returns the address that clients pass to QDBusConnection::connectToPeer().
bool QDBusServer::isConnected() const
Returns true if the server is listening.
QDBusError QDBusServer::lastError() const
Returns the error that stopped the server from listening.
void QDBusServer::newConnection(const QDBusConnection &connection)
This signal is emitted when a client has connected and authenticated. connection is the server's side of the connection.
void QDBusServer::setAnonymousAuthenticationAllowed(bool value)
Lets clients authenticate as anonymous if value is true, so that any user can connect.