Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QDBusConnection Class Reference

\inmodule QtDBus More...

#include <qdbusconnection.h>

+ Collaboration diagram for QDBusConnection:

Public Types

enum  BusType { SessionBus , SystemBus , ActivationBus }
 Specifies the type of the bus connection. More...
 
enum  RegisterOption {
  ExportAdaptors = 0x01 , ExportScriptableSlots = 0x10 , ExportScriptableSignals = 0x20 , ExportScriptableProperties = 0x40 ,
  ExportScriptableInvokables = 0x80 , ExportScriptableContents = 0xf0 , ExportNonScriptableSlots = 0x100 , ExportNonScriptableSignals = 0x200 ,
  ExportNonScriptableProperties = 0x400 , ExportNonScriptableInvokables = 0x800 , ExportNonScriptableContents = 0xf00 , ExportAllSlots = ExportScriptableSlots|ExportNonScriptableSlots ,
  ExportAllSignals = ExportScriptableSignals|ExportNonScriptableSignals , ExportAllProperties = ExportScriptableProperties|ExportNonScriptableProperties , ExportAllInvokables = ExportScriptableInvokables|ExportNonScriptableInvokables , ExportAllContents = ExportScriptableContents|ExportNonScriptableContents ,
  ExportAllSignal = ExportAllSignals , ExportChildObjects = 0x1000
}
 Specifies the options for registering objects with the connection. More...
 
enum  UnregisterMode { UnregisterNode , UnregisterTree }
 The mode for unregistering an object path: More...
 
enum  VirtualObjectRegisterOption { SingleNode = 0x0 , SubPath = 0x1 }
 
enum  ConnectionCapability { UnixFileDescriptorPassing = 0x0001 }
 

Public Member Functions

 QDBusConnection (const QString &name)
 Creates a QDBusConnection object attached to the connection with name name.
 
 QDBusConnection (const QDBusConnection &other)
 Creates a copy of the other connection.
 
 QDBusConnection (QDBusConnection &&other) noexcept
 
QDBusConnectionoperator= (QDBusConnection &&other) noexcept
 
QDBusConnectionoperator= (const QDBusConnection &other)
 Creates a copy of the connection other in this object.
 
 ~QDBusConnection ()
 Disposes of this object.
 
void swap (QDBusConnection &other) noexcept
 Swaps this QDBusConnection instance with other.
 
bool isConnected () const
 Returns true if this QDBusConnection object is connected.
 
QString baseService () const
 Returns the unique connection name for this connection, if this QDBusConnection object is connected, or an empty QString otherwise.
 
QDBusError lastError () const
 Returns the last error that happened in this connection.
 
QString name () const
 
ConnectionCapabilities connectionCapabilities () const
 
bool send (const QDBusMessage &message) const
 Sends the message over this connection, without waiting for a reply.
 
bool callWithCallback (const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout=-1) const
 Sends the message over this connection and returns immediately.
 
bool callWithCallback (const QDBusMessage &message, QObject *receiver, const char *slot, int timeout=-1) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QDBusMessage call (const QDBusMessage &message, QDBus::CallMode mode=QDBus::Block, int timeout=-1) const
 Sends the message over this connection and blocks, waiting for a reply, for at most timeout milliseconds.
 
QDBusPendingCall asyncCall (const QDBusMessage &message, int timeout=-1) const
 
bool connect (const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
 Connects the signal specified by the service, path, interface and name parameters to the slot slot in object receiver.
 
bool connect (const QString &service, const QString &path, const QString &interface, const QString &name, const QString &signature, QObject *receiver, const char *slot)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Connects the signal to the slot slot in object receiver.
 
bool connect (const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool disconnect (const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
 Disconnects the signal specified by the service, path, interface and name parameters from the slot slot in object receiver.
 
bool disconnect (const QString &service, const QString &path, const QString &interface, const QString &name, const QString &signature, QObject *receiver, const char *slot)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Disconnects the signal specified by the service, path, interface, name, and signature parameters from the slot slot in object receiver.
 
bool disconnect (const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool registerObject (const QString &path, QObject *object, RegisterOptions options=ExportAdaptors)
 Registers the object object at path path and returns true if the registration was successful.
 
bool registerObject (const QString &path, const QString &interface, QObject *object, RegisterOptions options=ExportAdaptors)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void unregisterObject (const QString &path, UnregisterMode mode=UnregisterNode)
 Unregisters an object that was registered with the registerObject() at the object path given by path and, if mode is QDBusConnection::UnregisterTree, all of its sub-objects too.
 
QObjectobjectRegisteredAt (const QString &path) const
 Return the object that was registered with the registerObject() at the object path given by path.
 
bool registerVirtualObject (const QString &path, QDBusVirtualObject *object, VirtualObjectRegisterOption options=SingleNode)
 
bool registerService (const QString &serviceName)
 Attempts to register the serviceName on the D-Bus server and returns true if the registration succeeded.
 
bool unregisterService (const QString &serviceName)
 Unregisters the service serviceName that was previously registered with registerService() and returns true if it succeeded.
 
QDBusConnectionInterfaceinterface () const
 Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connection.
 
voidinternalPointer () const
 

Static Public Member Functions

static QDBusConnection connectToBus (BusType type, const QString &name)
 Opens a connection of type type to one of the known buses and associate with it the connection name name.
 
static QDBusConnection connectToBus (const QString &address, const QString &name)
 Opens a connection to a private bus on address address and associate with it the connection name name.
 
static QDBusConnection connectToPeer (const QString &address, const QString &name)
 
static void disconnectFromBus (const QString &name)
 Closes the bus connection of name name.
 
static void disconnectFromPeer (const QString &name)
 
static QByteArray localMachineId ()
 
static QDBusConnection sessionBus ()
 Returns a QDBusConnection object opened with the session bus.
 
static QDBusConnection systemBus ()
 Returns a QDBusConnection object opened with the system bus.
 

Protected Member Functions

 QDBusConnection (QDBusConnectionPrivate *dd)
 

Friends

class QDBusConnectionPrivate
 

Detailed Description

\inmodule QtDBus

Since
4.2

The QDBusConnection class represents a connection to the D-Bus bus daemon.

This class is the initial point in a D-Bus session. Using it, you can get access to remote objects, interfaces; connect remote signals to your object's slots; register objects, etc.

D-Bus connections are created using the connectToBus() function, which opens a connection to the server daemon and does the initial handshaking, associating that connection with a name. Further attempts to connect using the same name will return the same connection.

The connection is then torn down using the disconnectFromBus() function.

Once disconnected, calling connectToBus() will not reestablish a connection, you must create a new QDBusConnection instance.

As a convenience for the two most common connection types, the sessionBus() and systemBus() functions return open connections to the session server daemon and the system server daemon, respectively. Those connections are opened when first used and are closed when the QCoreApplication destructor is run.

D-Bus also supports peer-to-peer connections, without the need for a bus server daemon. Using this facility, two applications can talk to each other and exchange messages. This can be achieved by passing an address to connectToBus() function, which was opened by another D-Bus application using QDBusServer.

Definition at line 41 of file qdbusconnection.h.

Member Enumeration Documentation

◆ BusType

Specifies the type of the bus connection.

The valid bus types are:

\value SessionBus the session bus, associated with the running desktop session \value SystemBus the system bus, used to communicate with system-wide processes \value ActivationBus the activation bus, the "alias" for the bus that started the service

On the Session Bus, one can find other applications by the same user that are sharing the same desktop session (hence the name). On the System Bus, however, processes shared for the whole system are usually found.

Enumerator
SessionBus 
SystemBus 
ActivationBus 

Definition at line 47 of file qdbusconnection.h.

◆ ConnectionCapability

Since
4.8

This enum describes the available capabilities for a D-Bus connection.

\value UnixFileDescriptorPassing enables passing of Unix file descriptors to other processes (see QDBusUnixFileDescriptor)

See also
connectionCapabilities()
Enumerator
UnixFileDescriptorPassing 

Definition at line 93 of file qdbusconnection.h.

◆ RegisterOption

Specifies the options for registering objects with the connection.

The possible values are:

\value ExportAdaptors export the contents of adaptors found in this object

\value ExportScriptableSlots export this object's scriptable slots \value ExportScriptableSignals export this object's scriptable signals \value ExportScriptableProperties export this object's scriptable properties \value ExportScriptableInvokables export this object's scriptable invokables \value ExportScriptableContents shorthand form for ExportScriptableSlots | ExportScriptableSignals | ExportScriptableProperties

\value ExportNonScriptableSlots export this object's non-scriptable slots \value ExportNonScriptableSignals export this object's non-scriptable signals \value ExportNonScriptableProperties export this object's non-scriptable properties \value ExportNonScriptableInvokables export this object's non-scriptable invokables \value ExportNonScriptableContents shorthand form for ExportNonScriptableSlots | ExportNonScriptableSignals | ExportNonScriptableProperties

\value ExportAllSlots export all of this object's slots \value ExportAllSignals export all of this object's signals \value ExportAllProperties export all of this object's properties \value ExportAllInvokables export all of this object's invokables \value ExportAllContents export all of this object's contents \value ExportChildObjects export this object's child objects

See also
registerObject(), QDBusAbstractAdaptor, {usingadaptors.html}{Using adaptors}
Enumerator
ExportAdaptors 
ExportScriptableSlots 
ExportScriptableSignals 
ExportScriptableProperties 
ExportScriptableInvokables 
ExportScriptableContents 
ExportNonScriptableSlots 
ExportNonScriptableSignals 
ExportNonScriptableProperties 
ExportNonScriptableInvokables 
ExportNonScriptableContents 
ExportAllSlots 
ExportAllSignals 
ExportAllProperties 
ExportAllInvokables 
ExportAllContents 
ExportAllSignal 
ExportChildObjects 

Definition at line 49 of file qdbusconnection.h.

◆ UnregisterMode

The mode for unregistering an object path:

\value UnregisterNode unregister this node only: do not unregister child objects \value UnregisterTree unregister this node and all its sub-tree

Note, however, if this object was registered with the ExportChildObjects option, UnregisterNode will unregister the child objects too.

Enumerator
UnregisterNode 
UnregisterTree 

Definition at line 80 of file qdbusconnection.h.

◆ VirtualObjectRegisterOption

Since
4.8

Specifies the options for registering virtual objects with the connection. The possible values are:

\value SingleNode register a virtual object to handle one path only \value SubPath register a virtual object so that it handles all sub paths

See also
registerVirtualObject(), QDBusVirtualObject
Enumerator
SingleNode 
SubPath 

Definition at line 86 of file qdbusconnection.h.

Constructor & Destructor Documentation

◆ QDBusConnection() [1/4]

QDBusConnection::QDBusConnection ( const QString & name)
explicit

Creates a QDBusConnection object attached to the connection with name name.

This does not open the connection. You have to call connectToBus() to open it.

Definition at line 151 of file qdbusconnection.cpp.

References QDBusConnectionManager::instance(), and manager.

Referenced by connectToBus(), connectToBus(), connectToPeer(), sessionBus(), and systemBus().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ QDBusConnection() [2/4]

QDBusConnection::QDBusConnection ( const QDBusConnection & other)

Creates a copy of the other connection.

Definition at line 170 of file qdbusconnection.cpp.

References other(), QBasicAtomicInteger< T >::ref(), and QDBusConnectionPrivate::ref.

+ Here is the call graph for this function:

◆ QDBusConnection() [3/4]

QDBusConnection::QDBusConnection ( QDBusConnection && other)
inlinenoexcept

Definition at line 100 of file qdbusconnection.h.

References other().

+ Here is the call graph for this function:

◆ ~QDBusConnection()

QDBusConnection::~QDBusConnection ( )

Disposes of this object.

This does not close the connection: you have to call disconnectFromBus() to do that.

Definition at line 192 of file qdbusconnection.cpp.

References QObject::deleteLater(), QBasicAtomicInteger< T >::deref(), and QDBusConnectionPrivate::ref.

+ Here is the call graph for this function:

◆ QDBusConnection() [4/4]

QDBusConnection::QDBusConnection ( QDBusConnectionPrivate * dd)
explicitprotected

Creates a connection object with the given dd as private object.

Definition at line 181 of file qdbusconnection.cpp.

References QBasicAtomicInteger< T >::ref(), and QDBusConnectionPrivate::ref.

+ Here is the call graph for this function:

Member Function Documentation

◆ asyncCall()

QDBusPendingCall QDBusConnection::asyncCall ( const QDBusMessage & message,
int timeout = -1 ) const
Since
4.5 Sends the message over this connection and returns immediately. This function is suitable for method calls only. It returns an object of type QDBusPendingCall which can be used to track the status of the reply.

If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds). This timeout is also the upper limit for waiting in QDBusPendingCall::waitForFinished().

See the QDBusInterface::asyncCall() function for a more friendly way of placing calls.

Note
Method calls to objects registered by the application itself are never asynchronous due to implementation limitations.

Definition at line 438 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, priv(), and QDBusConnectionPrivate::sendWithReplyAsync().

Referenced by QIBusProxy::GetProperty().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ baseService()

QString QDBusConnection::baseService ( ) const

Returns the unique connection name for this connection, if this QDBusConnection object is connected, or an empty QString otherwise.

A Unique Connection Name is a string in the form ":x.xxx" (where x are decimal digits) that is assigned by the D-Bus server daemon upon connection. It uniquely identifies this client in the bus.

This function returns an empty QString for peer-to-peer connections.

Definition at line 840 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::baseService.

Referenced by QDBusMenuConnection::registerTrayIconWithWatcher().

+ Here is the caller graph for this function:

◆ call()

QDBusMessage QDBusConnection::call ( const QDBusMessage & message,
QDBus::CallMode mode = QDBus::Block,
int timeout = -1 ) const

Sends the message over this connection and blocks, waiting for a reply, for at most timeout milliseconds.

This function is suitable for method calls only. It returns the reply message as its return value, which will be either of type QDBusMessage::ReplyMessage or QDBusMessage::ErrorMessage.

If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds).

See the QDBusInterface::call() function for a more friendly way of placing calls.

Warning
If mode is QDBus::BlockWithGui, this function will reenter the Qt event loop in order to wait for the reply. During the wait, it may deliver signals and other method calls to your application. Therefore, it must be prepared to handle a reentrancy whenever a call is placed with call().

Definition at line 398 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, QDBusMessage::createError(), QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage(), QDBusConnectionPrivate::lastError, QDBus::NoBlock, QDBusConnectionPrivate::send(), and QDBusConnectionPrivate::sendWithReply().

Referenced by QDBusAbstractInterfacePrivate::property().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ callWithCallback() [1/2]

bool QDBusConnection::callWithCallback ( const QDBusMessage & message,
QObject * receiver,
const char * returnMethod,
const char * errorMethod,
int timeout = -1 ) const

Sends the message over this connection and returns immediately.

When the reply is received, the method returnMethod is called in the receiver object. If an error occurs, the method errorMethod will be called instead.

If no reply is received within timeout milliseconds, an automatic error will be delivered indicating the expiration of the call. The default timeout is -1, which will be replaced with an implementation-defined value that is suitable for inter-process communications (generally, 25 seconds).

This function is suitable for method calls only. It is guaranteed that the slot will be called exactly once with the reply, as long as the parameter types match and no error occurs.

Returns true if the message was sent, or false if the message could not be sent.

Definition at line 338 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage(), QDBusConnectionPrivate::lastError, and QDBusConnectionPrivate::sendWithReplyAsync().

Referenced by callWithCallback(), and QDBusMenuConnection::registerTrayIconWithWatcher().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ callWithCallback() [2/2]

bool QDBusConnection::callWithCallback ( const QDBusMessage & message,
QObject * receiver,
const char * returnMethod,
int timeout = -1 ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Deprecated
Sends the message over this connection and returns immediately. When the reply is received, the method returnMethod is called in the receiver object.

This function is suitable for method calls only. It is guaranteed that the slot will be called exactly once with the reply, as long as the parameter types match and no error occurs.

This function is dangerous because it cannot report errors, including the expiration of the timeout.

Returns true if the message was sent, or false if the message could not be sent.

Definition at line 369 of file qdbusconnection.cpp.

References callWithCallback().

+ Here is the call graph for this function:

◆ connect() [1/3]

bool QDBusConnection::connect ( const QString & service,
const QString & path,
const QString & interface,
const QString & name,
const QString & signature,
QObject * receiver,
const char * slot )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Connects the signal to the slot slot in object receiver.

Unlike the previous connect() overload, this function allows one to specify the parameter signature to be connected using the signature variable. The function will then verify that this signature can be delivered to the slot specified by slot and return false otherwise.

Returns true if the connection was successful.

Note
This function verifies that the signal signature matches the slot's parameters, but it does not verify that the actual signal exists with the given signature in the remote service.

Definition at line 482 of file qdbusconnection.cpp.

References connect(), and interface().

+ Here is the call graph for this function:

◆ connect() [2/3]

bool QDBusConnection::connect ( const QString & service,
const QString & path,
const QString & interface,
const QString & name,
const QStringList & argumentMatch,
const QString & signature,
QObject * receiver,
const char * slot )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Connects the signal to the slot slot in object receiver. Unlike the previous connect() overload, this function allows one to specify the parameter signature to be connected using the signature variable. The function will then verify that this signature can be delivered to the slot specified by slot and return false otherwise.

The argumentMatch parameter lists the string parameters to be matched, in sequential order. Note that, to match an empty string, you need to pass a QString that is empty but not null (i.e., QString("")). A null QString skips matching at that position.

Returns true if the connection was successful.

Note
This function verifies that the signal signature matches the slot's parameters, but it does not verify that the actual signal exists with the given signature in the remote service.

Definition at line 512 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, QDBusConnectionPrivate::connectSignal(), interface(), QDBusUtil::isValidBusName(), QDBusUtil::isValidInterfaceName(), QDBusUtil::isValidObjectPath(), and qWarning.

+ Here is the call graph for this function:

◆ connect() [3/3]

bool QDBusConnection::connect ( const QString & service,
const QString & path,
const QString & interface,
const QString & name,
QObject * receiver,
const char * slot )

Connects the signal specified by the service, path, interface and name parameters to the slot slot in object receiver.

The arguments service and path can be empty, denoting a connection to any signal of the (interface, name) pair, from any remote application.

Returns true if the connection was successful.

Warning
The signal will only be delivered to the slot if the parameters match. This verification can be done only when the signal is received, not at connection time.

Definition at line 459 of file qdbusconnection.cpp.

References connect(), and interface().

Referenced by QIBusProxy::QIBusProxy(), connect(), and connect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connectionCapabilities()

QDBusConnection::ConnectionCapabilities QDBusConnection::connectionCapabilities ( ) const
Since
4.8

Returns the capabilities of this connection as negotiated with the bus server or peer. If this QDBusConnection is not connected, this function returns no capabilities.

Definition at line 874 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connectionCapabilities().

+ Here is the call graph for this function:

◆ connectToBus() [1/2]

QDBusConnection QDBusConnection::connectToBus ( BusType type,
const QString & name )
static

Opens a connection of type type to one of the known buses and associate with it the connection name name.

Returns a QDBusConnection object associated with that connection.

Definition at line 220 of file qdbusconnection.cpp.

References QDBusConnection(), d, QDBusConnectionManager::instance(), manager, and qdbus_loadLibDBus().

Referenced by QIBusPlatformInputContextPrivate::createConnection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connectToBus() [2/2]

QDBusConnection QDBusConnection::connectToBus ( const QString & address,
const QString & name )
static

Opens a connection to a private bus on address address and associate with it the connection name name.

Returns a QDBusConnection object associated with that connection.

Definition at line 235 of file qdbusconnection.cpp.

References QDBusConnection(), d, QDBusConnectionManager::instance(), manager, and qdbus_loadLibDBus().

+ Here is the call graph for this function:

◆ connectToPeer()

QDBusConnection QDBusConnection::connectToPeer ( const QString & address,
const QString & name )
static
Since
4.8

Opens a peer-to-peer connection on address address and associate with it the connection name name. Returns a QDBusConnection object associated with that connection.

Definition at line 252 of file qdbusconnection.cpp.

References QDBusConnection(), d, QDBusConnectionManager::instance(), manager, and qdbus_loadLibDBus().

+ Here is the call graph for this function:

◆ disconnect() [1/3]

bool QDBusConnection::disconnect ( const QString & service,
const QString & path,
const QString & interface,
const QString & name,
const QString & signature,
QObject * receiver,
const char * slot )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Disconnects the signal specified by the service, path, interface, name, and signature parameters from the slot slot in object receiver.

The arguments must be the same as passed to the connect() function.

Returns true if the disconnection was successful.

Definition at line 566 of file qdbusconnection.cpp.

References disconnect(), and interface().

+ Here is the call graph for this function:

◆ disconnect() [2/3]

bool QDBusConnection::disconnect ( const QString & service,
const QString & path,
const QString & interface,
const QString & name,
const QStringList & argumentMatch,
const QString & signature,
QObject * receiver,
const char * slot )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Disconnects the signal specified by the service, path, interface, name, argumentMatch, and signature parameters from the slot slot in object receiver. The arguments must be the same as passed to the connect() function.

Returns true if the disconnection was successful.

Definition at line 584 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, QDBusConnectionPrivate::disconnectSignal(), interface(), and QDBusUtil::isValidInterfaceName().

+ Here is the call graph for this function:

◆ disconnect() [3/3]

bool QDBusConnection::disconnect ( const QString & service,
const QString & path,
const QString & interface,
const QString & name,
QObject * receiver,
const char * slot )

Disconnects the signal specified by the service, path, interface and name parameters from the slot slot in object receiver.

The arguments must be the same as passed to the connect() function.

Returns true if the disconnection was successful.

Definition at line 550 of file qdbusconnection.cpp.

References disconnect(), and interface().

+ Here is the call graph for this function:

◆ disconnectFromBus()

void QDBusConnection::disconnectFromBus ( const QString & name)
static

Closes the bus connection of name name.

Note that if there are still QDBusConnection objects associated with the same connection, the connection will not be closed until all references are dropped. However, no further references can be created using the QDBusConnection constructor.

Definition at line 272 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::ClientMode, QDBusConnectionManager::instance(), and manager.

Referenced by QDBusMenuConnection::~QDBusMenuConnection(), QIBusPlatformInputContextPrivate::~QIBusPlatformInputContextPrivate(), and QIBusPlatformInputContext::socketChanged().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnectFromPeer()

void QDBusConnection::disconnectFromPeer ( const QString & name)
static
Since
4.8

Closes the peer connection of name name.

Note that if there are still QDBusConnection objects associated with the same connection, the connection will not be closed until all references are dropped. However, no further references can be created using the QDBusConnection constructor.

Definition at line 291 of file qdbusconnection.cpp.

References QDBusConnectionManager::instance(), manager, and QDBusConnectionPrivate::PeerMode.

+ Here is the call graph for this function:

◆ interface()

QDBusConnectionInterface * QDBusConnection::interface ( ) const

Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connection.

Definition at line 786 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::busService, QDBusConnectionPrivate::ClientMode, and QDBusConnectionPrivate::mode.

Referenced by bluetoothdVersion(), connect(), connect(), connect(), disconnect(), disconnect(), disconnect(), registerObject(), registerService(), and unregisterService().

+ Here is the caller graph for this function:

◆ internalPointer()

void * QDBusConnection::internalPointer ( ) const
Since
4.8

Returns the internal, implementation-defined pointer for this connection. Currently, this returns a DBusConnection* pointer, without changing the reference count. It is the responsibility of the caller to call dbus_connection_ref if it wants to store the pointer.

Definition at line 803 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection.

◆ isConnected()

bool QDBusConnection::isConnected ( ) const

Returns true if this QDBusConnection object is connected.

Definition at line 811 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection.

Referenced by QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(), QDBusInterfacePrivate::QDBusInterfacePrivate(), QDBusMenuConnection::~QDBusMenuConnection(), and QDBusAbstractInterfacePrivate::initOwnerTracking().

+ Here is the caller graph for this function:

◆ lastError()

QDBusError QDBusConnection::lastError ( ) const

Returns the last error that happened in this connection.

This function is provided for low-level code. If you're using QDBusInterface::call(), error codes are reported by its return value.

See also
QDBusInterface, QDBusMessage

Definition at line 825 of file qdbusconnection.cpp.

References QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage(), and QDBusConnectionPrivate::lastError.

+ Here is the call graph for this function:

◆ localMachineId()

QByteArray QDBusConnection::localMachineId ( )
static
Since
4.8 Returns the local machine ID as known to the D-Bus system. Each node or host that runs D-Bus has a unique identifier that can be used to distinguish it from other hosts if they are sharing resources like the filesystem.

Note that the local machine ID is not guaranteed to be persistent across boots of the system, so this identifier should not be stored in persistent storage (like the filesystem). It is guaranteed to remain constant only during the lifetime of this boot session.

Definition at line 972 of file qdbusconnection.cpp.

Referenced by QIBusPlatformInputContextPrivate::getSocketPath().

+ Here is the caller graph for this function:

◆ name()

QString QDBusConnection::name ( ) const
Since
4.5

Returns the connection name for this connection, as given as the name parameter to connectToBus().

The connection name can be used to uniquely identify actual underlying connections to buses. Copies made from a single connection will always implicitly share the underlying connection, and hence will have the same connection name.

Inversely, two connections having different connection names will always either be connected to different buses, or have a different unique name (as returned by baseService()) on that bus.

See also
connectToBus(), disconnectFromBus()

Definition at line 862 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::name.

Referenced by QDBusServiceWatcher::setConnection().

+ Here is the caller graph for this function:

◆ objectRegisteredAt()

QObject * QDBusConnection::objectRegisteredAt ( const QString & path) const

Return the object that was registered with the registerObject() at the object path given by path.

Definition at line 747 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::ObjectTreeNode::children, QDBusConnectionPrivate::connection, QList< T >::constBegin(), QList< T >::constEnd(), QDBusConnectionPrivate::ObjectTreeNode::flags, i, QDBusUtil::isValidObjectPath(), it, lock, QDBusConnectionPrivate::ObjectTreeNode::obj, ObjectRegisteredAtAction, Q_ASSERT_X, QDBusConnectionPrivate::rootNode, QStringView::split(), SubPath, and QDBusConnectionPrivate::VirtualObject.

+ Here is the call graph for this function:

◆ operator=() [1/2]

QDBusConnection & QDBusConnection::operator= ( const QDBusConnection & other)

Creates a copy of the connection other in this object.

Note that the connection this object referenced before the copy, is not spontaneously disconnected.

See also
disconnectFromBus()

Definition at line 205 of file qdbusconnection.cpp.

References QObject::deleteLater(), QBasicAtomicInteger< T >::deref(), other(), and QDBusConnectionPrivate::ref.

+ Here is the call graph for this function:

◆ operator=() [2/2]

QDBusConnection & QDBusConnection::operator= ( QDBusConnection && other)
inlinenoexcept

Definition at line 101 of file qdbusconnection.h.

References other(), and swap().

+ Here is the call graph for this function:

◆ registerObject() [1/2]

bool QDBusConnection::registerObject ( const QString & path,
const QString & interface,
QObject * object,
RegisterOptions options = ExportAdaptors )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
5.5

Registers the object object at path path with interface name interface and returns true if the registration was successful. The options parameter specifies how much of the object object will be exposed through D-Bus.

This function does not replace existing objects: if there is already an object registered at path path, this function will return false. Use unregisterObject() to unregister it first.

The ExportChildObjects flag exports child objects on D-Bus based on the path of the registered objects and the QObject::objectName of the child. Therefore, it is important for the child object to have an object name.

You cannot register an object as a child object of an object that was registered with ExportChildObjects.

Definition at line 638 of file qdbusconnection.cpp.

References QList< T >::begin(), QDBusConnectionPrivate::ObjectTreeNode::children, QDBusConnectionPrivate::connection, QList< T >::end(), ExportChildObjects, QDBusConnectionPrivate::ObjectTreeNode::flags, i, QList< T >::insert(), interface(), QDBusConnectionPrivate::ObjectTreeNode::interfaceName, QList< T >::isEmpty(), QDBusUtil::isValidObjectPath(), it, QDBusConnectionPrivate::ObjectTreeNode::obj, Q_ASSERT_X, QDBusConnectionPrivate::registerObject(), RegisterObjectAction, QDBusConnectionPrivate::rootNode, QStringView::split(), SubPath, and QDBusConnectionPrivate::VirtualObject.

+ Here is the call graph for this function:

◆ registerObject() [2/2]

bool QDBusConnection::registerObject ( const QString & path,
QObject * object,
RegisterOptions options = ExportAdaptors )

Registers the object object at path path and returns true if the registration was successful.

The options parameter specifies how much of the object object will be exposed through D-Bus.

This function does not replace existing objects: if there is already an object registered at path path, this function will return false. Use unregisterObject() to unregister it first.

The ExportChildObjects flag exports child objects on D-Bus based on the path of the registered objects and the QObject::objectName of the child. Therefore, it is important for the child object to have an object name.

You cannot register an object as a child object of an object that was registered with ExportChildObjects.

Definition at line 614 of file qdbusconnection.cpp.

References registerObject().

Referenced by registerObject(), QDBusMenuConnection::registerTrayIcon(), QDBusMenuConnection::registerTrayIconMenu(), and registerVirtualObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerService()

bool QDBusConnection::registerService ( const QString & serviceName)

Attempts to register the serviceName on the D-Bus server and returns true if the registration succeeded.

The registration will fail if the name is already registered by another application.

See also
unregisterService(), QDBusConnectionInterface::registerService()

Definition at line 886 of file qdbusconnection.cpp.

References interface(), registerService(), and QDBusConnectionPrivate::registerService().

Referenced by registerService().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerVirtualObject()

bool QDBusConnection::registerVirtualObject ( const QString & path,
QDBusVirtualObject * treeNode,
VirtualObjectRegisterOption options = SingleNode )
Since
4.8 Registers a QDBusTreeNode for a path. It can handle a path including all child paths, thus handling multiple DBus nodes.

To unregister a QDBusTreeNode use the unregisterObject() function with its path.

Definition at line 721 of file qdbusconnection.cpp.

References registerObject(), and QDBusConnectionPrivate::VirtualObject.

+ Here is the call graph for this function:

◆ send()

bool QDBusConnection::send ( const QDBusMessage & message) const

Sends the message over this connection, without waiting for a reply.

This is suitable for errors, signals, and return values as well as calls whose return values are not necessary.

Returns true if the message was queued successfully, false otherwise.

Definition at line 307 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage(), QDBusConnectionPrivate::lastError, and QDBusConnectionPrivate::send().

Referenced by QDBusContext::sendErrorReply(), and QDBusContext::sendErrorReply().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sessionBus()

QDBusConnection QDBusConnection::sessionBus ( )
static

Returns a QDBusConnection object opened with the session bus.

The object reference returned by this function is valid until the application terminates, at which point the connection will be closed and the object deleted.

Definition at line 918 of file qdbusconnection.cpp.

References QDBusConnection(), QDBusConnectionManager::instance(), manager, and SessionBus.

Referenced by DBusConnection::DBusConnection(), QXdgDesktopPortalTheme::QXdgDesktopPortalTheme(), checkDBusGlobalMenuAvailable(), sendReply(), and QGenericUnixServices::setApplicationBadge().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap()

void QDBusConnection::swap ( QDBusConnection & other)
inlinenoexcept

Swaps this QDBusConnection instance with other.

Definition at line 105 of file qdbusconnection.h.

References d, other(), and qt_ptr_swap().

+ Here is the call graph for this function:

◆ systemBus()

QDBusConnection QDBusConnection::systemBus ( )
static

Returns a QDBusConnection object opened with the system bus.

The object reference returned by this function is valid until the QCoreApplication's destructor is run, when the connection will be closed and the object, deleted.

Definition at line 934 of file qdbusconnection.cpp.

References QDBusConnection(), QDBusConnectionManager::instance(), manager, and SystemBus.

Referenced by NeardHelper::NeardHelper(), QNearFieldTargetPrivateImpl::QNearFieldTargetPrivateImpl(), QNetworkManagerInterface::QNetworkManagerInterface(), QtBluezDiscoveryManager::QtBluezDiscoveryManager(), QtBluezPeripheralApplication::QtBluezPeripheralApplication(), QNetworkManagerInterface::~QNetworkManagerInterface(), QtBluezDiscoveryManager::~QtBluezDiscoveryManager(), adapterWithDBusPeripheralInterface(), bluetoothdVersion(), QBluetoothSocketPrivateBluezDBus::connectToServiceHelper(), QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler(), QtBluezPeripheralConnectionManager::disconnectDevices(), QLowEnergyControllerPrivateBluezDBus::discoverServiceDetails(), QLowEnergyControllerPrivateBluezDBus::discoverServices(), findAdapterForAddress(), findRemoteDevicePath(), getPrimaryDevice(), QBluetoothSocketPrivateBluezDBus::localAddress(), QBluetoothSocketPrivateBluezDBus::localName(), nameOfRemoteCentral(), QBluetoothSocketPrivateBluezDBus::peerAddress(), QBluetoothSocketPrivateBluez::peerName(), QBluetoothSocketPrivateBluezDBus::peerName(), Q_GLOBAL_STATIC_WITH_ARGS(), OrgBluezGattCharacteristic1Adaptor::ReadValue(), OrgBluezGattDescriptor1Adaptor::ReadValue(), QtBluezPeripheralApplication::registerApplication(), QtBluezDiscoveryManager::registerDiscoveryInterest(), QtBluezPeripheralGattObject::registerObject(), QLeDBusAdvertiser::Release(), QtBluezPeripheralConnectionManager::remoteDeviceAccessEvent(), QBluetoothLocalDevicePrivate::requestPairing(), QLeDBusAdvertiser::startAdvertising(), QLeDBusAdvertiser::stopAdvertising(), QtBluezPeripheralApplication::unregisterApplication(), QtBluezDiscoveryManager::unregisterDiscoveryInterest(), QtBluezPeripheralGattObject::unregisterObject(), OrgBluezGattCharacteristic1Adaptor::WriteValue(), and OrgBluezGattDescriptor1Adaptor::WriteValue().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unregisterObject()

void QDBusConnection::unregisterObject ( const QString & path,
UnregisterMode mode = UnregisterNode )

Unregisters an object that was registered with the registerObject() at the object path given by path and, if mode is QDBusConnection::UnregisterTree, all of its sub-objects too.

Note that you cannot unregister objects that were not registered with registerObject().

Definition at line 734 of file qdbusconnection.cpp.

References QDBusConnectionPrivate::connection, QDBusUtil::isValidObjectPath(), QDBusConnectionPrivate::unregisterObject(), and UnregisterObjectAction.

Referenced by QDBusMenuConnection::unregisterTrayIcon(), and QDBusMenuConnection::unregisterTrayIconMenu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unregisterService()

bool QDBusConnection::unregisterService ( const QString & serviceName)

Unregisters the service serviceName that was previously registered with registerService() and returns true if it succeeded.

See also
registerService(), QDBusConnectionInterface::unregisterService()

Definition at line 902 of file qdbusconnection.cpp.

References interface(), unregisterService(), and QDBusConnectionPrivate::unregisterService().

Referenced by unregisterService().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QDBusConnectionPrivate

friend class QDBusConnectionPrivate
friend

Definition at line 173 of file qdbusconnection.h.


The documentation for this class was generated from the following files: