Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Properties | Friends | List of all members
QDBusConnection Class Reference

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

#include <qdbusconnection.h>

Inheritance diagram for QDBusConnection:
QDBusDefaultConnection

Public Types

enum  BusType { SessionBus, SystemBus, ActivationBus }
 Specifies the type of the bus connection. More...
 
enum  ConnectionCapability { UnixFileDescriptorPassing = 0x0001 }
 This enum describes the available capabilities for a D-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,
  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 }
 Specifies the options for registering virtual objects with the connection. More...
 

Public Functions

QDBusPendingCall asyncCall (const QDBusMessage &message, int timeout=-1) const
 Sends the message over this connection and returns immediately. More...
 
QString baseService () const
 Returns the unique connection name for this connection, if this QDBusConnection object is connected, or an empty QString otherwise. More...
 
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. More...
 
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. More...
 
bool callWithCallback (const QDBusMessage &message, QObject *receiver, const char *slot, int timeout=-1) const
 Sends the message over this connection and returns immediately. More...
 
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. More...
 
bool connect (const QString &service, const QString &path, const QString &interface, const QString &name, const QString &signature, QObject *receiver, const char *slot)
 Connects the signal to the slot slot in object receiver. More...
 
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)
 Connects the signal to the slot slot in object receiver. More...
 
ConnectionCapabilities connectionCapabilities () const
 Returns the capabilities of this connection as negotiated with the bus server or peer. More...
 
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. More...
 
bool disconnect (const QString &service, const QString &path, const QString &interface, const QString &name, const QString &signature, QObject *receiver, const char *slot)
 Disconnects the signal specified by the service, path, interface, name, and signature parameters from the slot slot in object receiver. More...
 
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)
 Disconnects the signal specified by the service, path, interface, name, argumentMatch, and signature parameters from the slot slot in object receiver. More...
 
QDBusConnectionInterfaceinterface () const
 Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connection. More...
 
void * internalPointer () const
 
bool isConnected () const
 Returns true if this QDBusConnection object is connected. More...
 
QDBusError lastError () const
 Returns the last error that happened in this connection. More...
 
QString name () const
 Returns the connection name for this connection, as given as the name parameter to connectToBus(). More...
 
QObjectobjectRegisteredAt (const QString &path) const
 Return the object that was registered with the registerObject() at the object path given by path. More...
 
QDBusConnectionoperator= (const QDBusConnection &other)
 Creates a copy of the connection other in this object. More...
 
 QDBusConnection (const QString &name)
 Creates a QDBusConnection object attached to the connection with name name. More...
 
 QDBusConnection (const QDBusConnection &other)
 Creates a copy of the other connection. More...
 
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. More...
 
bool registerService (const QString &serviceName)
 Attempts to register the serviceName on the D-Bus server and returns true if the registration succeeded. More...
 
bool registerVirtualObject (const QString &path, QDBusVirtualObject *object, VirtualObjectRegisterOption options=SingleNode)
 Registers a QDBusTreeNode for a path. More...
 
bool send (const QDBusMessage &message) const
 Sends the message over this connection, without waiting for a reply. More...
 
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. More...
 
bool unregisterService (const QString &serviceName)
 Unregisters the service serviceName that was previously registered with registerService() and returns true if it succeeded. More...
 
 ~QDBusConnection ()
 Disposes of this object. More...
 

Static Public Functions

static QDBusConnection connectToBus (BusType type, const QString &name)
 Opens a connection of type type to one of the known busses and associate with it the connection name name. More...
 
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. More...
 
static QDBusConnection connectToPeer (const QString &address, const QString &name)
 Opens a peer-to-peer connection on address address and associate with it the connection name name. More...
 
static void disconnectFromBus (const QString &name)
 Closes the bus connection of name name. More...
 
static void disconnectFromPeer (const QString &name)
 Closes the peer connection of name name. More...
 
static QByteArray localMachineId ()
 Returns the local machine ID as known to the D-Bus system. More...
 
static QDBusConnection sender ()
 Returns the connection that sent the signal, if called in a slot activated by QDBus; otherwise it returns 0. More...
 
static QDBusConnection sessionBus ()
 Returns a QDBusConnection object opened with the session bus. More...
 
static QDBusConnection systemBus ()
 Returns a QDBusConnection object opened with the system bus. More...
 

Protected Functions

 QDBusConnection (QDBusConnectionPrivate *dd)
 Creates a connection object with the given dd as private object. More...
 

Properties

QDBusConnectionPrivated
 

Friends

class QDBusConnectionPrivate
 

Detailed Description

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

Attention
Module: QtDBus
Since
4.2

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 76 of file qdbusconnection.h.

Enumerations

◆ BusType

Specifies the type of the bus connection.

The valid bus types are:

  • SessionBus the session bus, associated with the running desktop session
  • SystemBus the system bus, used to communicate with system-wide processes
  • 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 82 of file qdbusconnection.h.

◆ ConnectionCapability

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

Since
4.8
  • UnixFileDescriptorPassing enables passing of Unix file descriptors to other processes (see QDBusUnixFileDescriptor)
See also
connectionCapabilities()
Enumerator
UnixFileDescriptorPassing 

Definition at line 126 of file qdbusconnection.h.

◆ RegisterOption

Specifies the options for registering objects with the connection.

The possible values are:

  • ExportAdaptors export the contents of adaptors found in this object
  • ExportScriptableSlots export this object's scriptable slots
  • ExportScriptableSignals export this object's scriptable signals
  • ExportScriptableProperties export this object's scriptable properties
  • ExportScriptableInvokables export this object's scriptable invokables
  • ExportScriptableContents shorthand form for ExportScriptableSlots | ExportScriptableSignals | ExportScriptableProperties
  • ExportNonScriptableSlots export this object's non-scriptable slots
  • ExportNonScriptableSignals export this object's non-scriptable signals
  • ExportNonScriptableProperties export this object's non-scriptable properties
  • ExportNonScriptableInvokables export this object's non-scriptable invokables
  • ExportNonScriptableContents shorthand form for ExportNonScriptableSlots | ExportNonScriptableSignals | ExportNonScriptableProperties
  • ExportAllSlots export all of this object's slots
  • ExportAllSignals export all of this object's signals
  • ExportAllProperties export all of this object's properties
  • ExportAllInvokables export all of this object's invokables
  • ExportAllContents export all of this object's contents
  • 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 
ExportChildObjects 

Definition at line 83 of file qdbusconnection.h.

83  {
84  ExportAdaptors = 0x01,
85 
86  ExportScriptableSlots = 0x10,
91 
97 
103 
104 #ifndef Q_QDOC
105  // Qt 4.2 had a misspelling here
106  ExportAllSignal = ExportAllSignals,
107 #endif
108  ExportChildObjects = 0x1000
109  // Reserved = 0xff000000
110  };

◆ UnregisterMode

The mode for unregistering an object path:

  • UnregisterNode unregister this node only: do not unregister child objects
  • 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 111 of file qdbusconnection.h.

◆ VirtualObjectRegisterOption

Specifies the options for registering virtual objects with the connection.

Warning
This function is not part of the public interface.
Since
4.8

The possible values are:

  • SingleNode register a virtual object to handle one path only
  • SubPath register a virtual object so that it handles all sub paths
See also
registerVirtualObject(), QDBusVirtualObject
Enumerator
SingleNode 
SubPath 

Definition at line 117 of file qdbusconnection.h.

117  {
118  SingleNode = 0x0,
119  SubPath = 0x1
120  // Reserved = 0xff000000
121  };

Constructors and Destructors

◆ QDBusConnection() [1/3]

QDBusConnection::QDBusConnection ( const QString name)

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 289 of file qdbusconnection.cpp.

290 {
291  if (name.isEmpty()) {
292  d = 0;
293  } else {
294  QMutexLocker locker(&_q_manager()->mutex);
295  d = _q_manager()->connection(name);
296  if (d)
297  d->ref.ref();
298  }
299 }
bool ref()
Atomically increments the value of this QAtomicInt.
DBusConnection * connection
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusConnectionPrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ QDBusConnection() [2/3]

QDBusConnection::QDBusConnection ( const QDBusConnection other)

Creates a copy of the other connection.

Definition at line 304 of file qdbusconnection.cpp.

305 {
306  d = other.d;
307  if (d)
308  d->ref.ref();
309 }
bool ref()
Atomically increments the value of this QAtomicInt.
QDBusConnectionPrivate * d

◆ ~QDBusConnection()

QDBusConnection::~QDBusConnection ( )

Disposes of this object.

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

Definition at line 329 of file qdbusconnection.cpp.

330 {
331  if (d && !d->ref.deref())
332  d->deleteYourself();
333 }
bool deref()
Atomically decrements the value of this QAtomicInt.
QDBusConnectionPrivate * d

◆ QDBusConnection() [3/3]

QDBusConnection::QDBusConnection ( QDBusConnectionPrivate dd)
explicitprotected

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

Warning
This function is not part of the public interface.

Definition at line 318 of file qdbusconnection.cpp.

319 {
320  d = dd;
321  if (d)
322  d->ref.ref();
323 }
bool ref()
Atomically increments the value of this QAtomicInt.
QDBusConnectionPrivate * d

Functions

◆ asyncCall()

QDBusPendingCall QDBusConnection::asyncCall ( const QDBusMessage message,
int  timeout = -1 
) const

Sends the message over this connection and returns immediately.

Since
4.5 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.

Definition at line 662 of file qdbusconnection.cpp.

663 {
664  if (!d || !d->connection) {
665  return QDBusPendingCall(0); // null pointer -> disconnected
666  }
667 
668  QDBusPendingCallPrivate *priv = d->sendWithReplyAsync(message, 0, 0, 0, timeout);
669  return QDBusPendingCall(priv);
670 }
The QDBusPendingCall class refers to one pending asynchronous call.
DBusConnection * connection
QDBusPendingCallPrivate * sendWithReplyAsync(const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout=-1)
QDBusConnectionPrivate * d
static const QMetaObjectPrivate * priv(const uint *data)

◆ 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 1083 of file qdbusconnection.cpp.

1084 {
1085  return d ? d->baseService : QString();
1086 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDBusConnectionPrivate * d

◆ 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 622 of file qdbusconnection.cpp.

Referenced by do_dbus_call(), and QDBusAbstractInterfacePrivate::property().

623 {
624  if (!d || !d->connection) {
626  QLatin1String("Not connected to D-Bus server"));
627  if (d)
628  d->lastError = err;
629 
630  return QDBusMessage::createError(err);
631  }
632 
633  if (mode != QDBus::NoBlock)
634  return d->sendWithReply(message, mode, timeout);
635 
636  d->send(message);
637  QDBusMessage retval;
638  retval << QVariant(); // add one argument (to avoid .at(0) problems)
639  return retval;
640 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static QDBusMessage createError(const QString &name, const QString &msg)
Constructs a new DBus message representing an error, with the given name and msg. ...
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
DBusConnection * connection
QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout=-1)
QDBusConnectionPrivate * d
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
int send(const QDBusMessage &message)

◆ 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 559 of file qdbusconnection.cpp.

562 {
563  if (!d || !d->connection) {
565  QLatin1String("Not connected to D-BUS server"));
566  if (d)
567  d->lastError = err;
568  return false;
569  }
570  return d->sendWithReplyAsync(message, receiver, returnMethod, errorMethod, timeout) != 0;
571 }
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
DBusConnection * connection
QDBusPendingCallPrivate * sendWithReplyAsync(const QDBusMessage &message, QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout=-1)
QDBusConnectionPrivate * d

◆ callWithCallback() [2/2]

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

Sends the message over this connection and returns immediately.

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

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 593 of file qdbusconnection.cpp.

595 {
596  return callWithCallback(message, receiver, returnMethod, 0, timeout);
597 }
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.

◆ connect() [1/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 683 of file qdbusconnection.cpp.

Referenced by QOfonoManagerInterface::connectNotify(), QConnmanManagerInterface::connectNotify(), QOfonoModemInterface::connectNotify(), QConnmanProfileInterface::connectNotify(), QOfonoNetworkRegistrationInterface::connectNotify(), QOfonoNetworkOperatorInterface::connectNotify(), QConnmanServiceInterface::connectNotify(), QOfonoSimInterface::connectNotify(), QConnmanTechnologyInterface::connectNotify(), QOfonoDataConnectionManagerInterface::connectNotify(), QOfonoPrimaryDataContextInterface::connectNotify(), QOfonoSmsInterface::connectNotify(), QNetworkSessionPrivateImpl::QNetworkSessionPrivateImpl(), QIcdEngine::requestUpdate(), QNetworkManagerInterface::setConnections(), QNetworkManagerInterfaceAccessPoint::setConnections(), QNetworkManagerInterfaceDevice::setConnections(), QNetworkManagerInterfaceDeviceWired::setConnections(), QNetworkManagerInterfaceDeviceWireless::setConnections(), QNetworkManagerSettings::setConnections(), QNetworkManagerSettingsConnection::setConnections(), QNetworkManagerConnectionActive::setConnections(), and QIcdEngine::startListeningStateSignalsForAllConnections().

685 {
686  return connect(service, path, interface, name, QStringList(), QString(), receiver, slot);
687 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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...

◆ connect() [2/3]

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

Connects the signal to the slot slot in object receiver.

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

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 709 of file qdbusconnection.cpp.

712 {
713  return connect(service, path, interface, name, QStringList(), signature, receiver, slot);
714 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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...

◆ connect() [3/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 
)

Connects the signal to the slot slot in object receiver.

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

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 742 of file qdbusconnection.cpp.

745 {
746 
747  if (!receiver || !slot || !d || !d->connection)
748  return false;
749  if (interface.isEmpty() && name.isEmpty())
750  return false;
751  if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface)) {
752 #ifndef QT_NO_DEBUG
753  qWarning("QDBusConnection::connect: interface name '%s' is not valid", interface.toLatin1().constData());
754 #endif
755  return false;
756  }
757  if (!service.isEmpty() && !QDBusUtil::isValidBusName(service)) {
758 #ifndef QT_NO_DEBUG
759  qWarning("QDBusConnection::connect: service name '%s' is not valid", service.toLatin1().constData());
760 #endif
761  return false;
762  }
763  if (!path.isEmpty() && !QDBusUtil::isValidObjectPath(path)) {
764 #ifndef QT_NO_DEBUG
765  qWarning("QDBusConnection::connect: object path '%s' is not valid", path.toLatin1().constData());
766 #endif
767  return false;
768  }
769 
771  return d->connectSignal(service, path, interface, name, argumentMatch, signature, receiver, slot);
772 }
bool isValidObjectPath(const QString &path)
Returns true if path is valid object path.
Definition: qdbusutil.cpp:515
DBusConnection * connection
bool isValidInterfaceName(const QString &ifaceName)
Returns true if this is ifaceName is a valid interface name.
Definition: qdbusutil.cpp:367
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
bool connectSignal(const QString &service, const QString &path, const QString &interface, const QString &name, const QStringList &argumentMatch, const QString &signature, QObject *receiver, const char *slot)
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QDBusConnectionPrivate * d
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isValidBusName(const QString &busName)
Returns true if busName is a valid bus name.
Definition: qdbusutil.cpp:435

◆ connectionCapabilities()

QDBusConnection::ConnectionCapabilities QDBusConnection::connectionCapabilities ( ) const

Returns the capabilities of this connection as negotiated with the bus server or peer.

Since
4.8

If this QDBusConnection is not connected, this function returns no capabilities.

Definition at line 1123 of file qdbusconnection.cpp.

1124 {
1125  return d ? d->capabilities : ConnectionCapabilities(0);
1126 }
QDBusConnection::ConnectionCapabilities capabilities
QDBusConnectionPrivate * d

◆ connectToBus() [1/2]

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

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

Returns a QDBusConnection object associated with that connection.

Definition at line 357 of file qdbusconnection.cpp.

Referenced by QDBusConnectionConstructor::connectToBus(), and QNetworkSessionPrivateImpl::QNetworkSessionPrivateImpl().

358 {
359 // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
360 // "Cannot create connection without a Q[Core]Application instance");
361  if (!qdbus_loadLibDBus()) {
363  return QDBusConnection(d);
364  }
365 
366  QMutexLocker locker(&_q_manager()->mutex);
367 
368  QDBusConnectionPrivate *d = _q_manager()->connection(name);
369  if (d || name.isEmpty())
370  return QDBusConnection(d);
371 
372  d = new QDBusConnectionPrivate;
373  DBusConnection *c = 0;
375  switch (type) {
376  case SystemBus:
377  c = q_dbus_bus_get_private(DBUS_BUS_SYSTEM, error);
378  break;
379  case SessionBus:
380  c = q_dbus_bus_get_private(DBUS_BUS_SESSION, error);
381  break;
382  case ActivationBus:
383  c = q_dbus_bus_get_private(DBUS_BUS_STARTER, error);
384  break;
385  }
386  d->setConnection(c, error); //setConnection does the error handling for us
387 
388  _q_manager()->setConnection(name, d);
389 
390  QDBusConnection retval(d);
391 
392  // create the bus service
393  // will lock in QDBusConnectionPrivate::connectRelay()
394  d->setBusService(retval);
395 
396  return retval;
397 }
int type
Definition: qmetatype.cpp:239
unsigned char c[8]
Definition: qnumeric_p.h:62
#define error(msg)
DBusConnection * connection
QDBusConnection(const QString &name)
Creates a QDBusConnection object attached to the connection with name name.
friend class QDBusConnectionPrivate
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusConnectionPrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDBusConnection class represents a connection to the D-Bus bus daemon.
bool qdbus_loadLibDBus()
void setBusService(const QDBusConnection &connection)
void setConnection(DBusConnection *connection, const QDBusErrorInternal &error)

◆ 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 403 of file qdbusconnection.cpp.

405 {
406 // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
407 // "Cannot create connection without a Q[Core]Application instance");
408  if (!qdbus_loadLibDBus()) {
410  return QDBusConnection(d);
411  }
412 
413  QMutexLocker locker(&_q_manager()->mutex);
414 
415  QDBusConnectionPrivate *d = _q_manager()->connection(name);
416  if (d || name.isEmpty())
417  return QDBusConnection(d);
418 
419  d = new QDBusConnectionPrivate;
420  // setConnection does the error handling for us
422  DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);
423  if (c) {
424  if (!q_dbus_bus_register(c, error)) {
425  q_dbus_connection_unref(c);
426  c = 0;
427  }
428  }
429  d->setConnection(c, error);
430  _q_manager()->setConnection(name, d);
431 
432  QDBusConnection retval(d);
433 
434  // create the bus service
435  // will lock in QDBusConnectionPrivate::connectRelay()
436  d->setBusService(retval);
437 
438  return retval;
439 }
unsigned char c[8]
Definition: qnumeric_p.h:62
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
#define error(msg)
DBusConnection * connection
QDBusConnection(const QString &name)
Creates a QDBusConnection object attached to the connection with name name.
friend class QDBusConnectionPrivate
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusConnectionPrivate * d
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDBusConnection class represents a connection to the D-Bus bus daemon.
bool qdbus_loadLibDBus()
void setBusService(const QDBusConnection &connection)
void setConnection(DBusConnection *connection, const QDBusErrorInternal &error)

◆ connectToPeer()

QDBusConnection QDBusConnection::connectToPeer ( const QString address,
const QString name 
)
static

Opens a peer-to-peer connection on address address and associate with it the connection name name.

Since
4.8

Returns a QDBusConnection object associated with that connection.

Definition at line 449 of file qdbusconnection.cpp.

451 {
452 // Q_ASSERT_X(QCoreApplication::instance(), "QDBusConnection::addConnection",
453 // "Cannot create connection without a Q[Core]Application instance");
454  if (!qdbus_loadLibDBus()) {
456  return QDBusConnection(d);
457  }
458 
459  QMutexLocker locker(&_q_manager()->mutex);
460 
461  QDBusConnectionPrivate *d = _q_manager()->connection(name);
462  if (d || name.isEmpty())
463  return QDBusConnection(d);
464 
465  d = new QDBusConnectionPrivate;
466  // setPeer does the error handling for us
468  DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);
469 
470  d->setPeer(c, error);
471  _q_manager()->setConnection(name, d);
472 
473  QDBusConnection retval(d);
474 
475  return retval;
476 }
unsigned char c[8]
Definition: qnumeric_p.h:62
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
#define error(msg)
DBusConnection * connection
QDBusConnection(const QString &name)
Creates a QDBusConnection object attached to the connection with name name.
friend class QDBusConnectionPrivate
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QDBusConnectionPrivate * d
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDBusConnection class represents a connection to the D-Bus bus daemon.
void setPeer(DBusConnection *connection, const QDBusErrorInternal &error)
bool qdbus_loadLibDBus()

◆ disconnect() [1/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 781 of file qdbusconnection.cpp.

Referenced by QIcdEngine::cancelAsyncConfigurationUpdate().

783 {
784  return disconnect(service, path, interface, name, QStringList(), QString(), receiver, slot);
785 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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 sl...

◆ disconnect() [2/3]

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

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

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

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

Returns true if the disconnection was successful.

Definition at line 800 of file qdbusconnection.cpp.

803 {
804  return disconnect(service, path, interface, name, QStringList(), signature, receiver, slot);
805 }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
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 sl...

◆ disconnect() [3/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 
)

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

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

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

Returns true if the disconnection was successful.

Definition at line 821 of file qdbusconnection.cpp.

824 {
825  if (!receiver || !slot || !d || !d->connection)
826  return false;
827  if (!interface.isEmpty() && !QDBusUtil::isValidInterfaceName(interface))
828  return false;
829  if (interface.isEmpty() && name.isEmpty())
830  return false;
831 
833  return d->disconnectSignal(service, path, interface, name, argumentMatch, signature, receiver, slot);
834 }
DBusConnection * connection
bool isValidInterfaceName(const QString &ifaceName)
Returns true if this is ifaceName is a valid interface name.
Definition: qdbusutil.cpp:367
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
SignalHookHash::Iterator disconnectSignal(SignalHookHash::Iterator &it)
QDBusConnectionPrivate * d

◆ 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 486 of file qdbusconnection.cpp.

Referenced by QDBusConnectionConstructor::disconnectFromBus(), and QNetworkSessionPrivateImpl::~QNetworkSessionPrivateImpl().

487 {
488  if (_q_manager()) {
489  QMutexLocker locker(&_q_manager()->mutex);
490  QDBusConnectionPrivate *d = _q_manager()->connection(name);
492  return;
493  _q_manager()->removeConnection(name);
494  }
495 }
DBusConnection * connection
QDBusConnectionPrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ disconnectFromPeer()

void QDBusConnection::disconnectFromPeer ( const QString name)
static

Closes the peer connection of name name.

Since
4.8

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 510 of file qdbusconnection.cpp.

511 {
512  if (_q_manager()) {
513  QMutexLocker locker(&_q_manager()->mutex);
514  QDBusConnectionPrivate *d = _q_manager()->connection(name);
515  if (d && d->mode != QDBusConnectionPrivate::PeerMode)
516  return;
517  _q_manager()->removeConnection(name);
518  }
519 }
DBusConnection * connection
QDBusConnectionPrivate * d
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ interface()

QDBusConnectionInterface * QDBusConnection::interface ( ) const

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

Definition at line 1029 of file qdbusconnection.cpp.

Referenced by QScriptDBusConnection::QScriptDBusConnection().

1030 {
1031  if (!d)
1032  return 0;
1033  return d->busService;
1034 }
QDBusConnectionPrivate * d
QDBusConnectionInterface * busService

◆ internalPointer()

void * QDBusConnection::internalPointer ( ) const
Warning
This function is not part of the public interface.
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 1046 of file qdbusconnection.cpp.

1047 {
1048  return d ? d->connection : 0;
1049 }
DBusConnection * connection
QDBusConnectionPrivate * d

◆ isConnected()

bool QDBusConnection::isConnected ( ) const

Returns true if this QDBusConnection object is connected.

Definition at line 1054 of file qdbusconnection.cpp.

Referenced by QDBusAbstractInterface::QDBusAbstractInterface(), QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(), and QDBusInterfacePrivate::QDBusInterfacePrivate().

1055 {
1056  return d && d->connection && q_dbus_connection_get_is_connected(d->connection);
1057 }
DBusConnection * connection
QDBusConnectionPrivate * d

◆ 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 1068 of file qdbusconnection.cpp.

Referenced by QNetworkManagerSettingsConnection::setConnections().

1069 {
1070  return d ? d->lastError : QDBusError();
1071 }
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QDBusConnectionPrivate * d

◆ localMachineId()

QByteArray QDBusConnection::localMachineId ( )
static

Returns the local machine ID as known to the D-Bus system.

Since
4.8 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 1256 of file qdbusconnection.cpp.

1257 {
1258  char *dbus_machine_id = q_dbus_get_local_machine_id();
1259  QByteArray result = dbus_machine_id;
1260  q_dbus_free(dbus_machine_id);
1261  return result;
1262 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ name()

QString QDBusConnection::name ( ) const

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

Since
4.5

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 1108 of file qdbusconnection.cpp.

Referenced by QDBusServiceWatcher::setConnection().

1109 {
1110  return d ? d->name : QString();
1111 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
QDBusConnectionPrivate * d

◆ 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 990 of file qdbusconnection.cpp.

991 {
992  Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registeredObject",
993  "Invalid object path given");
994  if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
995  return 0;
996 
997  QStringList pathComponents = path.split(QLatin1Char('/'));
998  if (pathComponents.last().isEmpty())
999  pathComponents.removeLast();
1000 
1001  // lower-bound search for where this object should enter in the tree
1004 
1005  int i = 1;
1006  while (node) {
1007  if (pathComponents.count() == i)
1008  return node->obj;
1010  return node->obj;
1011 
1013  qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponents.at(i));
1014  if (it == node->children.constEnd() || it->name != pathComponents.at(i))
1015  break; // node not found
1016 
1017  node = it;
1018  ++i;
1019  }
1020  return 0;
1021 }
bool isValidObjectPath(const QString &path)
Returns true if path is valid object path.
Definition: qdbusutil.cpp:515
#define it(className, varName)
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:252
void removeLast()
Removes the last item in the list.
Definition: qlist.h:287
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
DBusConnection * connection
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:249
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QDBusConnectionPrivate * d
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
static QReadWriteLock lock
Definition: proxyconf.cpp:399
if(void) toggleToolbarShown
const_iterator ConstIterator
Qt-style synonym for QVector::const_iterator.
Definition: qvector.h:279
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ operator=()

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 342 of file qdbusconnection.cpp.

343 {
344  if (other.d)
345  other.d->ref.ref();
346  if (d && !d->ref.deref())
347  d->deleteYourself();
348  d = other.d;
349  return *this;
350 }
bool ref()
Atomically increments the value of this QAtomicInt.
bool deref()
Atomically decrements the value of this QAtomicInt.
QDBusConnectionPrivate * d

◆ registerObject()

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.

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

Definition at line 848 of file qdbusconnection.cpp.

849 {
850  Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registerObject",
851  "Invalid object path given");
852  if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
853  return false;
854 
855  QStringList pathComponents = path.split(QLatin1Char('/'));
856  if (pathComponents.last().isEmpty())
857  pathComponents.removeLast();
859 
860  // lower-bound search for where this object should enter in the tree
862  int i = 1;
863  while (node) {
864  if (pathComponents.count() == i) {
865  // this node exists
866  // consider it free if there's no object here and the user is not trying to
867  // replace the object sub-tree
868  if (node->obj)
869  return false;
870 
872  // technically the check for children needs to go even deeper
873  if (options & SubPath) {
874  foreach (const QDBusConnectionPrivate::ObjectTreeNode &child, node->children) {
875  if (child.obj)
876  return false;
877  }
878  }
879  } else {
880  if ((options & ExportChildObjects && !node->children.isEmpty()))
881  return false;
882  }
883  // we can add the object here
884  node->obj = object;
885  node->flags = options;
886 
887  d->registerObject(node);
888  //qDebug("REGISTERED FOR %s", path.toLocal8Bit().constData());
889  return true;
890  }
891 
892  // if a virtual object occupies this path, return false
893  if (node->obj && (node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath)) {
894  qDebug("Cannot register object at %s because QDBusVirtualObject handles all sub-paths.",
895  qPrintable(path));
896  return false;
897  }
898 
899  // find the position where we'd insert the node
901  qLowerBound(node->children.begin(), node->children.end(), pathComponents.at(i));
902  if (it != node->children.end() && it->name == pathComponents.at(i)) {
903  // match: this node exists
904  node = it;
905 
906  // are we allowed to go deeper?
907  if (node->flags & ExportChildObjects) {
908  // we're not
909  qDebug("Cannot register object at %s because %s exports its own child objects",
910  qPrintable(path), qPrintable(pathComponents.at(i)));
911  return false;
912  }
913  } else {
914  // add entry
915  node = node->children.insert(it, pathComponents.at(i));
916  }
917 
918  // iterate
919  ++i;
920  }
921 
922  Q_ASSERT_X(false, "QDBusConnection::registerObject", "The impossible happened");
923  return false;
924 }
bool isValidObjectPath(const QString &path)
Returns true if path is valid object path.
Definition: qdbusutil.cpp:515
#define it(className, varName)
void removeLast()
Removes the last item in the list.
Definition: qlist.h:287
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
DBusConnection * connection
iterator Iterator
Qt-style synonym for QVector::iterator.
Definition: qvector.h:278
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
Q_CORE_EXPORT void qDebug(const char *,...)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QDBusConnectionPrivate * d
void insert(int i, const T &t)
Inserts value at index position i in the vector.
Definition: qvector.h:362
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
void registerObject(const ObjectTreeNode *node)
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
T & last()
Returns a reference to the last item in the list.
Definition: qlist.h:284
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ 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 1135 of file qdbusconnection.cpp.

1136 {
1137  if (interface() && interface()->registerService(serviceName)) {
1138  if (d) d->registerService(serviceName);
1139  return true;
1140  }
1141  return false;
1142 }
QDBusConnectionInterface * interface() const
Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connecti...
bool registerService(const QString &serviceName)
Attempts to register the serviceName on the D-Bus server and returns true if the registration succeed...
QDBusConnectionPrivate * d
void registerService(const QString &serviceName)

◆ registerVirtualObject()

bool QDBusConnection::registerVirtualObject ( const QString path,
QDBusVirtualObject treeNode,
VirtualObjectRegisterOption  options = SingleNode 
)

Registers a QDBusTreeNode for a path.

Warning
This function is not part of the public interface.
Since
4.8 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 937 of file qdbusconnection.cpp.

939 {
940  int opts = options | QDBusConnectionPrivate::VirtualObject;
941  return registerObject(path, (QObject*) treeNode, (RegisterOptions) opts);
942 }
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...
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111

◆ 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 528 of file qdbusconnection.cpp.

Referenced by QDBusContext::sendErrorReply().

529 {
530  if (!d || !d->connection) {
532  QLatin1String("Not connected to D-BUS server"));
533  if (d)
534  d->lastError = err;
535  return false;
536  }
537  return d->send(message) != 0;
538 }
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
DBusConnection * connection
QDBusConnectionPrivate * d
int send(const QDBusMessage &message)

◆ sender()

QDBusConnection QDBusConnection::sender ( )
static

Returns the connection that sent the signal, if called in a slot activated by QDBus; otherwise it returns 0.

Note
This class or function is not reentrant.
Please avoid this function. This function is not thread-safe, so if there's any other thread delivering a D-Bus call, this function may return the wrong connection. In new code, please use QDBusContext::connection() (see that class for a description on how to use it).

Definition at line 1213 of file qdbusconnection.cpp.

1214 {
1215  return QDBusConnection(_q_manager()->sender());
1216 }
static QDBusConnection sender()
Returns the connection that sent the signal, if called in a slot activated by QDBus; otherwise it ret...
QDBusConnection(const QString &name)
Creates a QDBusConnection object attached to the connection with name name.

◆ sessionBus()

_q_systemBusName 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 1189 of file qdbusconnection.cpp.

Referenced by QDBusConnectionConstructor::QDBusConnectionConstructor(), and QScriptDBusInterfaceConstructor::qscript_call().

1190 {
1191  return *_q_sessionBus();
1192 }

◆ 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 1194 of file qdbusconnection.cpp.

Referenced by QIcdEngine::ensureDBusConnection(), and QDBusConnectionConstructor::QDBusConnectionConstructor().

1195 {
1196  return *_q_systemBus();
1197 }
_q_systemBus

◆ 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 950 of file qdbusconnection.cpp.

951 {
952  if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
953  return;
954 
955  QStringList pathComponents = path.split(QLatin1Char('/'));
958  int i = 1;
959 
960  // find the object
961  while (node) {
962  if (pathComponents.count() == i || !path.compare(QLatin1String("/"))) {
963  // found it
964  node->obj = 0;
965  node->flags = 0;
966 
967  if (mode == UnregisterTree) {
968  // clear the sub-tree as well
969  node->children.clear(); // can't disconnect the objects because we really don't know if they can
970  // be found somewhere else in the path too
971  }
972 
973  return;
974  }
975 
977  qLowerBound(node->children.begin(), node->children.end(), pathComponents.at(i));
978  if (it == node->children.end() || it->name != pathComponents.at(i))
979  break; // node not found
980 
981  node = it;
982  ++i;
983  }
984 }
bool isValidObjectPath(const QString &path)
Returns true if path is valid object path.
Definition: qdbusutil.cpp:515
#define it(className, varName)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
DBusConnection * connection
iterator Iterator
Qt-style synonym for QVector::iterator.
Definition: qvector.h:278
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QDBusConnectionPrivate * d
Q_OUTOFLINE_TEMPLATE RandomAccessIterator qLowerBound(RandomAccessIterator begin, RandomAccessIterator end, const T &value)
Definition: qalgorithms.h:227
int compare(const QString &s) const
Definition: qstring.cpp:5037
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ 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 1151 of file qdbusconnection.cpp.

1152 {
1153  if (interface()->unregisterService(serviceName)) {
1154  if (d) d->unregisterService(serviceName);
1155  return true;
1156  }
1157  return false;
1158 }
QDBusConnectionInterface * interface() const
Returns a QDBusConnectionInterface object that represents the D-Bus server interface on this connecti...
bool unregisterService(const QString &serviceName)
Unregisters the service serviceName that was previously registered with registerService() and returns...
void unregisterService(const QString &serviceName)
QDBusConnectionPrivate * d

Friends and Related Functions

◆ QDBusConnectionPrivate

Definition at line 203 of file qdbusconnection.h.

Properties

◆ d

QDBusConnectionPrivate* QDBusConnection::d
private

Definition at line 204 of file qdbusconnection.h.

Referenced by QDBusConnectionPrivate::d(), operator=(), and QDBusConnection().


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