QDBusMessage 类

The QDBusMessage 类表示通过 D-Bus 总线发送 (或接收) 的一条消息。 更多...

头: #include <QDBusMessage>
qmake: QT += dbus
Since: Qt 4.2

公共类型

enum MessageType { MethodCallMessage, SignalMessage, ReplyMessage, ErrorMessage, InvalidMessage }

公共函数

QDBusMessage ()
QDBusMessage (const QDBusMessage & other )
~QDBusMessage ()
QList<QVariant> arguments () const
bool autoStartService () const
QDBusMessage createErrorReply (const QString name , const QString & msg ) const
QDBusMessage createErrorReply (const QDBusError & error ) const
QDBusMessage createErrorReply (QDBusError::ErrorType type , const QString & msg ) const
QDBusMessage createReply (const QList<QVariant> & arguments = QList<QVariant>()) const
QDBusMessage createReply (const QVariant & argument ) const
QString errorMessage () const
QString errorName () const
QString interface () const
bool isDelayedReply () const
bool isInteractiveAuthorizationAllowed () const
bool isReplyRequired () const
QString member () const
QString path () const
QString service () const
void setArguments (const QList<QVariant> & arguments )
void setAutoStartService (bool enable )
void setDelayedReply (bool enable ) const
void setInteractiveAuthorizationAllowed (bool enable )
QString signature () const
void swap (QDBusMessage & other )
QDBusMessage::MessageType type () const
QDBusMessage & operator<< (const QVariant & arg )
QDBusMessage & operator= (QDBusMessage && other )
QDBusMessage & operator= (const QDBusMessage & other )

静态公共成员

QDBusMessage createError (const QString & name , const QString & msg )
QDBusMessage createError (const QDBusError & error )
QDBusMessage createError (QDBusError::ErrorType type , const QString & msg )
QDBusMessage createMethodCall (const QString & service , const QString & path , const QString & interface , const QString & method )
QDBusMessage createSignal (const QString & path , const QString & interface , const QString & name )
QDBusMessage createTargetedSignal (const QString & service , const QString & path , const QString & interface , const QString & name )

详细描述

The QDBusMessage 类表示通过 D-Bus 总线发送 (或接收) 的一条消息。

此对象可以表示 4 种不同类型的任何一种消息 ( MessageType ) 可以出现在总线中:

  • 方法调用
  • 方法返回值
  • 信号发出
  • 错误代码

此类型对象的创建采用静态 createError (), createMethodCall () 和 createSignal () 函数。使用 QDBusConnection::send () 函数来发送消息。

成员类型文档编制

enum QDBusMessage:: MessageType

可能的消息类型:

常量 描述
QDBusMessage::MethodCallMessage 1 a message representing an outgoing or incoming method call
QDBusMessage::SignalMessage 4 a message representing an outgoing or incoming signal emission
QDBusMessage::ReplyMessage 2 a message representing the return values of a method call
QDBusMessage::ErrorMessage 3 a message representing an error condition in response to a method call
QDBusMessage::InvalidMessage 0 an invalid message: this is never set on messages received from D-Bus

成员函数文档编制

QDBusMessage:: QDBusMessage ()

构造空的,无效 QDBusMessage 对象。

另请参阅 createError (), createMethodCall (),和 createSignal ().

QDBusMessage:: QDBusMessage (const QDBusMessage & other )

构造副本对象,给定通过 other .

注意: QDBusMessage objects are shared. Modifications made to the copy will affect the original one as well. See setDelayedReply () 了解更多信息。

QDBusMessage:: ~QDBusMessage ()

处置对象并释放所保持的任何资源。

QList < QVariant > QDBusMessage:: arguments () const

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

另请参阅 setArguments ().

bool QDBusMessage:: autoStartService () const

返回自动启动标志,如设置通过 setAutoStartService (). By default, this flag is true, which means Qt D-Bus will auto start a service, if it is not running already.

该函数在 Qt 4.7 引入。

另请参阅 setAutoStartService ().

[static] QDBusMessage QDBusMessage:: createError (const QString & name , const QString & msg )

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

[static] QDBusMessage QDBusMessage:: createError (const QDBusError & error )

Constructs a new DBus message representing the given error .

[static] QDBusMessage QDBusMessage:: createError ( QDBusError::ErrorType type , const QString & msg )

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

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 .

QDBusMessage QDBusMessage:: createErrorReply (const QDBusError & error ) const

Constructs a new DBus message representing an error reply message, from the given error 对象。

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.

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

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 ().

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

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

QDBusMessage QDBusMessage:: createReply (const QVariant & argument ) const

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

[static] QDBusMessage 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.

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 () 函数。

[static] QDBusMessage QDBusMessage:: createTargetedSignal (const QString & service , 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 to a specific destination.

A DBus signal is emitted from one application and is received only by the application owning the destination service 名称。

The QDBusMessage object that is returned can be sent using the QDBusConnection::send () 函数。

该函数在 Qt 5.6 引入。

QString QDBusMessage:: errorMessage () const

Returns the human-readable message associated with the error that was received.

该函数在 Qt 4.3 引入。

QString QDBusMessage:: errorName () const

Returns the name of the error that was received.

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.

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.

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.

该函数在 Qt 5.12 引入。

另请参阅 setInteractiveAuthorizationAllowed ().

bool QDBusMessage:: isReplyRequired () const

Returns the flag that indicates if this message should see a reply or not. This is only meaningful for method call messages : any other kind of message cannot have replies and this function will always return false for them.

QString QDBusMessage:: member () const

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

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).

QString QDBusMessage:: service () const

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

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.

另请参阅 arguments ().

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.

该函数在 Qt 4.7 引入。

另请参阅 autoStartService ().

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 为 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.

另请参阅 isDelayedReply () 和 延迟回复 .

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.

该函数在 Qt 5.12 引入。

另请参阅 isInteractiveAuthorizationAllowed ().

QString QDBusMessage:: signature () const

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

void QDBusMessage:: swap ( QDBusMessage & other )

交换此 QDBusMessage 实例与 other .

QDBusMessage::MessageType QDBusMessage:: type () const

Returns the message type.

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.

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

移动赋值运算符。

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

Copies the contents of the object given by other .

注意: QDBusMessage objects are shared. Modifications made to the copy will affect the original one as well. See setDelayedReply () 了解更多信息。