Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QDBusMessage Class Reference

\inmodule QtDBus More...

#include <qdbusmessage.h>

+ Collaboration diagram for QDBusMessage:

Public Types

enum  MessageType {
  InvalidMessage , MethodCallMessage , ReplyMessage , ErrorMessage ,
  SignalMessage
}
 The possible message types: More...
 

Public Member Functions

 QDBusMessage ()
 Constructs an empty, invalid QDBusMessage object.
 
 QDBusMessage (const QDBusMessage &other)
 Constructs a copy of the object given by other.
 
QDBusMessageoperator= (QDBusMessage &&other) noexcept
 
QDBusMessageoperator= (const QDBusMessage &other)
 Copies the contents of the object given by other.
 
 ~QDBusMessage ()
 Disposes of the object and frees any resources that were being held.
 
void swap (QDBusMessage &other) noexcept
 Swaps this QDBusMessage instance with other.
 
QDBusMessage createReply (const QList< QVariant > &arguments=QList< QVariant >()) const
 Constructs a new DBus message representing a reply, with the given arguments.
 
QDBusMessage createReply (const QVariant &argument) const
 Constructs a new DBus message representing a reply, with the given argument.
 
QDBusMessage createErrorReply (const QString &name, const QString &msg) const
 Constructs a new DBus message representing an error reply message, with the given name and msg.
 
QDBusMessage createErrorReply (const QDBusError &err) const
 Constructs a new DBus message representing an error reply message, from the given error object.
 
QDBusMessage createErrorReply (QDBusError::ErrorType type, const QString &msg) const
 Constructs a new DBus reply message for the error type type using the message msg.
 
QString service () const
 Returns the name of the service or the bus address of the remote method call.
 
QString path () const
 Returns the path of the object that this message is being sent to (in the case of a method call) or being received from (for a signal).
 
QString interface () const
 Returns the interface of the method being called (in the case of a method call) or of the signal being received from.
 
QString member () const
 Returns the name of the signal that was emitted or the name of the method that was called.
 
QString errorName () const
 Returns the name of the error that was received.
 
QString errorMessage () const
 
MessageType type () const
 Returns the message type.
 
QString signature () const
 Returns the signature of the signal that was received or for the output arguments of a method call.
 
bool isReplyRequired () const
 Returns the flag that indicates if this message should see a reply or not.
 
void setDelayedReply (bool enable) const
 Sets whether the message will be replied later (if enable is true) or if an automatic reply should be generated by Qt D-Bus (if enable is false).
 
bool isDelayedReply () const
 Returns the delayed reply flag, as set by setDelayedReply().
 
void setAutoStartService (bool enable)
 Sets the auto start flag to enable.
 
bool autoStartService () const
 Returns the auto start flag, as set by setAutoStartService().
 
void setInteractiveAuthorizationAllowed (bool enable)
 Sets the interactive authorization flag to enable.
 
bool isInteractiveAuthorizationAllowed () const
 Returns the interactive authorization allowed flag, as set by setInteractiveAuthorizationAllowed().
 
void setArguments (const QList< QVariant > &arguments)
 Sets the arguments that are going to be sent over D-Bus to arguments.
 
QList< QVariantarguments () const
 Returns the list of arguments that are going to be sent or were received from D-Bus.
 
QDBusMessageoperator<< (const QVariant &arg)
 Appends the argument arg to the list of arguments to be sent over D-Bus in a method call or signal emission.
 

Static Public Member Functions

static QDBusMessage createSignal (const QString &path, const QString &interface, const QString &name)
 Constructs a new DBus message with the given path, interface and name, representing a signal emission.
 
static QDBusMessage createTargetedSignal (const QString &service, const QString &path, const QString &interface, const QString &name)
 
static QDBusMessage createMethodCall (const QString &destination, const QString &path, const QString &interface, const QString &method)
 Constructs a new DBus message representing a method call.
 
static QDBusMessage createError (const QString &name, const QString &msg)
 Constructs a new DBus message representing an error, with the given name and msg.
 
static QDBusMessage createError (const QDBusError &err)
 Constructs a new DBus message representing the given error.
 
static QDBusMessage createError (QDBusError::ErrorType type, const QString &msg)
 Constructs a new DBus message for the error type type using the message msg.
 

Friends

class QDBusMessagePrivate
 

Detailed Description

\inmodule QtDBus

Since
4.2

The QDBusMessage class represents one message sent or received over the D-Bus bus.

This object can represent any of the four different types of messages (MessageType) that can occur on the bus:

\list

  • Method calls
  • Method return values
  • Signal emissions
  • Error codes \endlist

Objects of this type are created with the static createError(), createMethodCall() and createSignal() functions. Use the QDBusConnection::send() function to send the messages.

Definition at line 21 of file qdbusmessage.h.

Member Enumeration Documentation

◆ MessageType

The possible message types:

\value MethodCallMessage a message representing an outgoing or incoming method call \value SignalMessage a message representing an outgoing or incoming signal emission \value ReplyMessage a message representing the return values of a method call \value ErrorMessage a message representing an error condition in response to a method call \value InvalidMessage an invalid message: this is never set on messages received from D-Bus

Enumerator
InvalidMessage 
MethodCallMessage 
ReplyMessage 
ErrorMessage 
SignalMessage 

Definition at line 24 of file qdbusmessage.h.

Constructor & Destructor Documentation

◆ QDBusMessage() [1/2]

QDBusMessage::QDBusMessage ( )

Constructs an empty, invalid QDBusMessage object.

See also
createError(), createMethodCall(), createSignal()

Definition at line 513 of file qdbusmessage.cpp.

References QDBusMessagePrivate.

Referenced by createErrorReply(), and createReply().

+ Here is the caller graph for this function:

◆ QDBusMessage() [2/2]

QDBusMessage::QDBusMessage ( const QDBusMessage other)

Constructs a copy of the object given by other.

Note: QDBusMessage objects are shared. Modifications made to the copy will affect the original one as well. See setDelayedReply() for more information.

Definition at line 525 of file qdbusmessage.cpp.

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

+ Here is the call graph for this function:

◆ ~QDBusMessage()

QDBusMessage::~QDBusMessage ( )

Disposes of the object and frees any resources that were being held.

Definition at line 534 of file qdbusmessage.cpp.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ arguments()

QList< QVariant > QDBusMessage::arguments ( ) const

Returns the list of arguments that are going to be sent or were received from D-Bus.

Definition at line 746 of file qdbusmessage.cpp.

References QDBusMessagePrivate::arguments.

Referenced by QDBusPendingReplyBase::argumentAt(), createReply(), operator<<(), QDBusConnectionPrivate::prepareReply(), qDBusPropertyGet(), qDBusPropertyGetAll(), qDBusPropertySet(), and setArguments().

+ Here is the caller graph for this function:

◆ autoStartService()

bool QDBusMessage::autoStartService ( ) const

Returns the auto start flag, as set by setAutoStartService().

By default, this flag is true, which means Qt D-Bus will auto start a service, if it is not running already.

See also
setAutoStartService()
Since
4.7

Definition at line 688 of file qdbusmessage.cpp.

References QDBusMessagePrivate::autoStartService.

◆ createError() [1/3]

QDBusMessage QDBusMessage::createError ( const QDBusError err)
inlinestatic

Constructs a new DBus message representing the given error.

Definition at line 47 of file qdbusmessage.h.

References QDBusError::message(), and QDBusError::name().

+ Here is the call graph for this function:

◆ createError() [2/3]

QDBusMessage QDBusMessage::createError ( const QString name,
const QString msg 
)
static

Constructs a new DBus message representing an error, with the given name and msg.

Definition at line 413 of file qdbusmessage.cpp.

References QObject::d_ptr, error, and ErrorMessage.

Referenced by QDBusConnection::call(), QDBusAbstractInterface::callWithArgumentList(), QDBusPendingCallPrivate::checkReceivedSignature(), createErrorReply(), QDBusPendingCall::fromError(), QDBusMessagePrivate::makeLocal(), QDBusConnectionPrivate::processFinishedCall(), and QDBusPendingCall::reply().

+ Here is the caller graph for this function:

◆ createError() [3/3]

QDBusMessage QDBusMessage::createError ( QDBusError::ErrorType  type,
const QString msg 
)
inlinestatic

Constructs a new DBus message for the error type type using the message msg.

Returns the DBus message.

Definition at line 49 of file qdbusmessage.h.

References QDBusError::errorString().

+ Here is the call graph for this function:

◆ createErrorReply() [1/3]

QDBusMessage QDBusMessage::createErrorReply ( const QDBusError err) const
inline

Constructs a new DBus message representing an error reply message, from the given error object.

Definition at line 56 of file qdbusmessage.h.

References QDBusError::message(), and QDBusError::name().

+ Here is the call graph for this function:

◆ createErrorReply() [2/3]

QDBusMessage QDBusMessage::createErrorReply ( const QString name,
const QString msg 
) const

Constructs a new DBus message representing an error reply message, with the given name and msg.

Definition at line 463 of file qdbusmessage.cpp.

References QDBusMessage(), createError(), QObject::d_ptr, QDBusMessagePrivate::localMessage, QDBusMessagePrivate::localReply, QDBusMessagePrivate::msg, Q_ASSERT, and reply.

Referenced by createErrorReply(), interfaceNotFoundError(), propertyNotFoundError(), propertyWriteReply(), OrgBluezGattCharacteristic1Adaptor::ReadValue(), OrgBluezGattDescriptor1Adaptor::ReadValue(), OrgBluezGattCharacteristic1Adaptor::WriteValue(), and OrgBluezGattDescriptor1Adaptor::WriteValue().

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

◆ createErrorReply() [3/3]

QDBusMessage QDBusMessage::createErrorReply ( QDBusError::ErrorType  type,
const QString msg 
) const

Constructs a new DBus reply message for the error type type using the message msg.

Returns the DBus message.

Definition at line 500 of file qdbusmessage.cpp.

References createErrorReply(), QDBusError::errorString(), and QDBusMessagePrivate::parametersValidated.

+ Here is the call graph for this function:

◆ createMethodCall()

QDBusMessage QDBusMessage::createMethodCall ( const QString service,
const QString path,
const QString interface,
const QString method 
)
static

Constructs a new DBus message representing a method call.

A method call always informs its destination address (service, path, interface and method).

The DBus bus allows calling a method on a given remote object without specifying the destination interface, if the method name is unique. However, if two interfaces on the remote object export the same method name, the result is undefined (one of the two may be called or an error may be returned).

When using DBus in a peer-to-peer context (i.e., not on a bus), the service parameter is optional.

The QDBusInterface class provides a simpler abstraction to synchronous method calling.

This function returns a QDBusMessage object that can be sent with QDBusConnection::call().

Definition at line 396 of file qdbusmessage.cpp.

References interface(), method, MethodCallMessage, path(), and service().

Referenced by QXdgDesktopPortalTheme::QXdgDesktopPortalTheme(), QDBusAbstractInterface::asyncCallWithArgumentList(), QDBusAbstractInterface::callWithArgumentList(), QDBusAbstractInterface::callWithCallback(), QIBusProxy::GetProperty(), QDBusAbstractInterfacePrivate::property(), QDBusMenuConnection::registerTrayIconWithWatcher(), and QDBusAbstractInterfacePrivate::setProperty().

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

◆ createReply() [1/2]

QDBusMessage QDBusMessage::createReply ( const QList< QVariant > &  arguments = QList<QVariant>()) const

Constructs a new DBus message representing a reply, with the given arguments.

Definition at line 442 of file qdbusmessage.cpp.

References QDBusMessage(), arguments(), QObject::d_ptr, QDBusMessagePrivate::localMessage, QDBusMessagePrivate::localReply, QDBusMessagePrivate::msg, Q_ASSERT, reply, and ReplyMessage.

Referenced by createReply(), propertyWriteReply(), qDBusPropertyGet(), and qDBusPropertyGetAll().

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

◆ createReply() [2/2]

QDBusMessage QDBusMessage::createReply ( const QVariant argument) const

Constructs a new DBus message representing a reply, with the given argument.

Definition at line 482 of file qdbusmessage.cpp.

References argument, and createReply().

+ Here is the call graph for this function:

◆ createSignal()

QDBusMessage QDBusMessage::createSignal ( const QString path,
const QString interface,
const QString name 
)
static

Constructs a new DBus message with the given path, interface and name, representing a signal emission.

A DBus signal is emitted from one application and is received by all applications that are listening for that signal from that interface.

The QDBusMessage object that is returned can be sent using the QDBusConnection::send() function.

Definition at line 340 of file qdbusmessage.cpp.

References interface(), path(), and SignalMessage.

Referenced by QDBusConnectionPrivate::relaySignal(), and QGenericUnixServices::setApplicationBadge().

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

◆ createTargetedSignal()

QDBusMessage QDBusMessage::createTargetedSignal ( const QString service,
const QString path,
const QString interface,
const QString name 
)
static
Since
5.6

Constructs a new DBus message with the given path, interface and name, representing a signal emission to a specific destination.

A DBus signal is emitted from one application and is received only by the application owning the destination service name.

The QDBusMessage object that is returned can be sent using the QDBusConnection::send() function.

Definition at line 364 of file qdbusmessage.cpp.

References interface(), path(), service(), and SignalMessage.

+ Here is the call graph for this function:

◆ errorMessage()

QString QDBusMessage::errorMessage ( ) const
Since
4.3 Returns the human-readable message associated with the error that was received.

Definition at line 59 of file qdbusmessage.cpp.

References QDBusMessagePrivate::arguments, QList< T >::at(), ErrorMessage, QString::isEmpty(), QList< T >::isEmpty(), QDBusMessagePrivate::message, QVariant::toString(), and QDBusMessagePrivate::type.

Referenced by QDBusError::QDBusError(), operator<<(), and QDBusError::operator=().

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

◆ errorName()

QString QDBusMessage::errorName ( ) const

Returns the name of the error that was received.

Definition at line 592 of file qdbusmessage.cpp.

References ErrorMessage, QDBusMessagePrivate::name, and QDBusMessagePrivate::type.

Referenced by QDBusError::QDBusError(), operator<<(), and QDBusError::operator=().

+ Here is the caller graph for this function:

◆ interface()

QString QDBusMessage::interface ( ) const

Returns the interface of the method being called (in the case of a method call) or of the signal being received from.

Definition at line 574 of file qdbusmessage.cpp.

References QDBusMessagePrivate::interface.

Referenced by createMethodCall(), createSignal(), createTargetedSignal(), and operator<<().

+ Here is the caller graph for this function:

◆ isDelayedReply()

bool QDBusMessage::isDelayedReply ( ) const

Returns the delayed reply flag, as set by setDelayedReply().

By default, this flag is false, which means Qt D-Bus will generate automatic replies when necessary.

Definition at line 649 of file qdbusmessage.cpp.

References QDBusMessagePrivate::delayedReply.

Referenced by QDBusContext::isDelayedReply().

+ Here is the caller graph for this function:

◆ isInteractiveAuthorizationAllowed()

bool QDBusMessage::isInteractiveAuthorizationAllowed ( ) const

Returns the interactive authorization allowed flag, as set by setInteractiveAuthorizationAllowed().

By default this flag is false and the other end is expected to make any authorization decisions non-interactively and promptly.

See also
setInteractiveAuthorizationAllowed()
Since
5.12

Definition at line 726 of file qdbusmessage.cpp.

References QDBusMessagePrivate::interactiveAuthorizationAllowed.

◆ isReplyRequired()

bool QDBusMessage::isReplyRequired ( ) const

Returns the flag that indicates if this message should see a reply or not.

This is only meaningful for \l {MethodCallMessage}{method call messages}: any other kind of message cannot have replies and this function will always return false for them.

Definition at line 614 of file qdbusmessage.cpp.

References QDBusMessagePrivate::localMessage, MethodCallMessage, QDBusMessagePrivate::msg, and QDBusMessagePrivate::type.

◆ member()

QString QDBusMessage::member ( ) const

Returns the name of the signal that was emitted or the name of the method that was called.

Definition at line 582 of file qdbusmessage.cpp.

References ErrorMessage, QDBusMessagePrivate::name, and QDBusMessagePrivate::type.

Referenced by operator<<().

+ Here is the caller graph for this function:

◆ operator<<()

QDBusMessage & QDBusMessage::operator<< ( const QVariant arg)

Appends the argument arg to the list of arguments to be sent over D-Bus in a method call or signal emission.

Definition at line 756 of file qdbusmessage.cpp.

References QList< T >::append(), arg, and QDBusMessagePrivate::arguments.

+ Here is the call graph for this function:

◆ operator=() [1/2]

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

Copies the contents of the object given by other.

Note: QDBusMessage objects are shared. Modifications made to the copy will affect the original one as well. See setDelayedReply() for more information.

Definition at line 547 of file qdbusmessage.cpp.

References other(), and qAtomicAssign().

+ Here is the call graph for this function:

◆ operator=() [2/2]

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

Definition at line 34 of file qdbusmessage.h.

References other(), and swap().

+ Here is the call graph for this function:

◆ path()

QString QDBusMessage::path ( ) const

Returns the path of the object that this message is being sent to (in the case of a method call) or being received from (for a signal).

Definition at line 565 of file qdbusmessage.cpp.

References QDBusMessagePrivate::path.

Referenced by createMethodCall(), createSignal(), createTargetedSignal(), interfaceNotFoundError(), operator<<(), and propertyNotFoundError().

+ Here is the caller graph for this function:

◆ service()

QString QDBusMessage::service ( ) const

Returns the name of the service or the bus address of the remote method call.

Definition at line 556 of file qdbusmessage.cpp.

References QDBusMessagePrivate::service.

Referenced by createMethodCall(), createTargetedSignal(), and operator<<().

+ Here is the caller graph for this function:

◆ setArguments()

void QDBusMessage::setArguments ( const QList< QVariant > &  arguments)

Sets the arguments that are going to be sent over D-Bus to arguments.

Those will be the arguments to a method call or the parameters in the signal.

See also
arguments()

Definition at line 737 of file qdbusmessage.cpp.

References arguments(), and QDBusMessagePrivate::arguments.

Referenced by QDBusAbstractInterface::asyncCallWithArgumentList(), QDBusAbstractInterface::callWithArgumentList(), QDBusAbstractInterface::callWithCallback(), main(), and QDBusMenuConnection::registerTrayIconWithWatcher().

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

◆ setAutoStartService()

void QDBusMessage::setAutoStartService ( bool  enable)

Sets the auto start flag to enable.

This flag only makes sense for method call messages, where it tells the D-Bus server to either auto start the service responsible for the service name, or not to auto start it.

By default this flag is true, i.e. a service is autostarted. This means:

When the service that this method call is sent to is already running, the method call is sent to it. If the service is not running yet, the D-Bus daemon is requested to autostart the service that is assigned to this service name. This is handled by .service files that are placed in a directory known to the D-Bus server. These files then each contain a service name and the path to a program that should be executed when this service name is requested.

Since
4.7

Definition at line 674 of file qdbusmessage.cpp.

References QDBusMessagePrivate::autoStartService.

◆ setDelayedReply()

void QDBusMessage::setDelayedReply ( bool  enable) const

Sets whether the message will be replied later (if enable is true) or if an automatic reply should be generated by Qt D-Bus (if enable is false).

In D-Bus, all method calls must generate a reply to the caller, unless the caller explicitly indicates otherwise (see isReplyRequired()). QtDBus automatically generates such replies for any slots being called, but it also allows slots to indicate whether they will take responsibility of sending the reply at a later time, after the function has finished processing.

See also
{Delayed Replies}

Definition at line 639 of file qdbusmessage.cpp.

References QDBusMessagePrivate::delayedReply.

Referenced by QDBusContext::setDelayedReply().

+ Here is the caller graph for this function:

◆ setInteractiveAuthorizationAllowed()

void QDBusMessage::setInteractiveAuthorizationAllowed ( bool  enable)

Sets the interactive authorization flag to enable.

This flag only makes sense for method call messages, where it tells the D-Bus server that the caller of the method is prepared to wait for interactive authorization to take place (for instance via Polkit) before the actual method is processed.

By default this flag is false and the other end is expected to make any authorization decisions non-interactively and promptly.

The org.freedesktop.DBus.Error.InteractiveAuthorizationRequired error indicates that authorization failed, but could have succeeded if this flag had been set.

See also
isInteractiveAuthorizationAllowed()
Since
5.12

Definition at line 711 of file qdbusmessage.cpp.

References QDBusMessagePrivate::interactiveAuthorizationAllowed.

◆ signature()

QString QDBusMessage::signature ( ) const

Returns the signature of the signal that was received or for the output arguments of a method call.

Definition at line 603 of file qdbusmessage.cpp.

References QDBusMessagePrivate::signature.

Referenced by QDBusPendingCallPrivate::checkReceivedSignature(), and operator<<().

+ Here is the caller graph for this function:

◆ swap()

void QDBusMessage::swap ( QDBusMessage other)
inlinenoexcept

Swaps this QDBusMessage instance with other.

Definition at line 38 of file qdbusmessage.h.

References other(), and qt_ptr_swap().

+ Here is the call graph for this function:

◆ type()

Friends And Related Symbol Documentation

◆ QDBusMessagePrivate

friend class QDBusMessagePrivate
friend

Definition at line 87 of file qdbusmessage.h.

Referenced by QDBusMessage().


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