QDBusReply Class

The QDBusReply class stores the reply for a method call to a remote object. 更多...

头文件: #include <QDBusReply>
qmake: QT += dbus
开始支持版本: Qt 4.2

公有函数

QDBusReply(const QDBusMessage &reply)
QDBusReply(const QDBusPendingCall &pcall)
QDBusReply(const QDBusPendingReply<T> &reply)
QDBusReply(const QDBusError &error = QDBusError())
const QDBusError &error() const
const QDBusError &error()
bool isValid() const
Type value() const
operator Type() const
QDBusReply &operator=(const QDBusMessage &message)
QDBusReply &operator=(const QDBusPendingCall &pcall)
QDBusReply &operator=(const QDBusError &error)
QDBusReply &operator=(const QDBusReply &other)

详细描述

QDBusReply class stores the reply for a method call to a remote object.

QDBusReply 对象是 QDBusMessage 对象的子集, 表示远程方法调用的回复. 它仅包含第一个输出参数或错误代码, QDBusInterface的派生类允许将错误代码作为函数的返回参数.

你可以按以下方式使用QDBusReply:


  QDBusReply<QString> reply = interface->call("RemoteMethod");
  if (reply.isValid())
      // use the returned value
      useValue(reply.value());
  else
      // call failed. Show an error condition.
      showError(reply.error());

如果远程方法调用总会成功, 你可以跳过错误检查:


  QString reply = interface->call("RemoteMethod");

但是, 如果调用方法在某些情况下失败, QDBusReply::value() 返回值是默认构造函数的值. 它可能无法与有效值区分.

QDBusReply 对象用于没有输出参数或返回值的远程调用 (即., 它们具有 "void" 返回类型). 调用 isValid() 函数检查回复是否成功.

参见 QDBusMessage and QDBusInterface.

成员函数

QDBusReply::QDBusReply(const QDBusMessage &reply)

Automatically construct a QDBusReply object from the reply message reply, extracting the first return value from it if it is a success reply.

QDBusReply::QDBusReply(const QDBusPendingCall &pcall)

Automatically construct a QDBusReply object from the asynchronous pending call pcall. If the call isn't finished yet, QDBusReply will call QDBusPendingCall::waitForFinished(), which is a blocking operation.

If the return types patch, QDBusReply will extract the first return argument from the reply.

QDBusReply::QDBusReply(const QDBusPendingReply<T> &reply)

Constructs a QDBusReply object from the pending reply message, reply.

QDBusReply::QDBusReply(const QDBusError &error = QDBusError())

Constructs an error reply from the D-Bus error code given by error.

const QDBusError &QDBusReply::error() const

Returns the error code that was returned from the remote function call. If the remote call did not return an error (i.e., if it succeeded), then the QDBusError object that is returned will not be a valid error code (QDBusError::isValid() will return false).

参见 isValid().

const QDBusError &QDBusReply::error()

This is an overloaded function.

bool QDBusReply::isValid() const

Returns true if no error occurred; otherwise, returns false.

参见 error().

Type QDBusReply::value() const

Returns the remote function's calls return value. If the remote call returned with an error, the return value of this function is undefined and may be undistinguishable from a valid return value.

This function is not available if the remote call returns void.

QDBusReply::operator Type() const

Returns the same as value().

This function is not available if the remote call returns void.

QDBusReply &QDBusReply::operator=(const QDBusMessage &message)

Makes this object contain the reply specified by message message. If message is an error message, this function will copy the error code and message into this object

If message is a standard reply message and contains at least one parameter, it will be copied into this object, as long as it is of the correct type. If it's not of the same type as this QDBusError object, this function will instead set an error code indicating a type mismatch.

QDBusReply &QDBusReply::operator=(const QDBusPendingCall &pcall)

Makes this object contain the reply specified by the pending asynchronous call pcall. If the call is not finished yet, this function will call QDBusPendingCall::waitForFinished() to block until the reply arrives.

If pcall finishes with an error message, this function will copy the error code and message into this object

If pcall finished with a standard reply message and contains at least one parameter, it will be copied into this object, as long as it is of the correct type. If it's not of the same type as this QDBusError object, this function will instead set an error code indicating a type mismatch.

QDBusReply &QDBusReply::operator=(const QDBusError &error)

Sets this object to contain the error code given by error. You can later access it with error().

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

Makes this object be a copy of the object other.