QDBusError Class

QDBusError 类表示从 D-Bus 总线或总线上的远程应用程序接收到的错误。更多

Header: #include <QDBusError>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus

公共类型

enum ErrorType { NoError, Other, Failed, NoMemory, ServiceUnknown, …, InvalidInterface }

公共函数

bool isValid() const
QString message() const
QString name() const
void swap(QDBusError &other)
QDBusError::ErrorType type() const

静态公共成员

QString errorString(QDBusError::ErrorType error)

详细说明

在处理 D-Bus 总线服务或通过 D-Bus 处理远程应用程序时,可能会出现一些错误条件。这些错误条件有时会通过返回的错误值或 QDBusError 来提示。

C++ 和 Java 异常是 D-Bus 错误的有效类比:远程应用程序和总线可能决定抛出一个错误条件,而不是正常返回一个返回值。不过,Qt D-Bus 实现并不使用 C++ 异常抛出机制,因此您将在返回回复中收到 QDBusErrors(请参阅QDBusReply::error() )。

QDBusError 对象用于检查从总线和远程应用程序接收到的错误名称和信息。当从 D-Bus 调用时,不应自行创建此类对象来提示错误条件:而应使用QDBusMessage::createError() 和QDBusConnection::send() 。

另请参阅 QDBusConnection::send(),QDBusMessage, 和QDBusReply

成员类型文档

enum QDBusError::ErrorType

为便于验证 D-Bus 实现和总线守护进程本身产生的最常见 D-Bus 错误,QDBusError ,并与一组预定义值进行比较:

常量说明
QDBusError::NoError0QDBusError 无效(即调用成功)
QDBusError::Other1QDBusError 包含的错误不属于众所周知的错误之一
QDBusError::Failed2调用失败 (org.freedesktop.DBus.Error.Failed)
QDBusError::NoMemory3内存不足 (org.freedesktop.DBus.Error.NoMemory)
QDBusError::ServiceUnknown4不知道被调用的服务 (org.freedesktop.DBus.Error.ServiceUnknown)
QDBusError::NoReply5被调用方法没有在指定超时内回复 (org.freedesktop.DBus.Error.NoReply)
QDBusError::BadAddress6给出的地址无效 (org.freedesktop.DBus.Error.BadAddress)
QDBusError::NotSupported7不支持调用/操作 (org.freedesktop.DBus.Error.NotSupported)
QDBusError::LimitsExceeded8分配给该进程/调用/连接的限制超出了预定义值 (org.freedesktop.DBus.Error.LimitsExceeded)
QDBusError::AccessDenied9调用/操作试图访问不允许访问的资源 (org.freedesktop.DBus.Error.AccessDenied)
QDBusError::NoServer10文档没有说明这是什么(org.freedesktop.DBus.Error.NoServer)
QDBusError::Timeout11文档没有说明这是什么或如何使用(org.freedesktop.DBus.Error.Timeout)
QDBusError::NoNetwork12文档没有说明这是用来做什么的(org.freedesktop.DBus.Error.NoNetwork)
QDBusError::AddressInUse13QDBusServer 试图绑定到一个已被使用的地址 ( )org.freedesktop.DBus.Error.AddressInUse
QDBusError::Disconnected14调用/进程/消息是在QDBusConnection 断开连接后发送的 (org.freedesktop.DBus.Error.Disconnected)
QDBusError::InvalidArgs15传递给此调用/操作的参数无效 (org.freedesktop.DBus.Error.InvalidArgs)
QDBusError::UnknownMethod16在此对象/接口中没有找到所给参数的调用方法 (org.freedesktop.DBus.Error.UnknownMethod)
QDBusError::TimedOut17文档没有说明...... (org.freedesktop.DBus.Error.TimedOut)
QDBusError::InvalidSignature18类型签名无效或不兼容 (org.freedesktop.DBus.Error.InvalidSignature)
QDBusError::UnknownInterface19在此对象中不知道接口 (org.freedesktop.DBus.Error.UnknownInterface)
QDBusError::UnknownObject20对象路径指向一个不存在的对象 (org.freedesktop.DBus.Error.UnknownObject)
QDBusError::UnknownProperty21该接口中不存在该属性 (org.freedesktop.DBus.Error.UnknownProperty)
QDBusError::PropertyReadOnly22属性设置失败,因为该属性为只读 (org.freedesktop.DBus.Error.PropertyReadOnly)
QDBusError::InternalError23发生内部错误
QDBusError::InvalidObjectPath25提供的对象路径无效。
QDBusError::InvalidService24请求的服务无效。
QDBusError::InvalidMember27成员无效。
QDBusError::InvalidInterface26接口无效。

成员函数文档

[static] QString QDBusError::errorString(QDBusError::ErrorType error)

返回与错误条件相关的错误名称error

bool QDBusError::isValid() const

如果是有效错误条件(即出错),则返回true ,否则返回 false。

QString QDBusError::message() const

返回调用者与此错误相关联的信息。错误信息是由实现定义的,通常包含一个人类可读的错误代码,但这并不意味着它适合您的最终用户。

QString QDBusError::name() const

返回该错误的名称。错误名称与 D-Bus 接口名称类似,如org.freedesktop.DBus.InvalidArgs

另请参见 type().

[noexcept] void QDBusError::swap(QDBusError &other)

将此错误与other 互换。该操作速度非常快,从未出现过故障。

QDBusError::ErrorType QDBusError::type() const

返回此错误的ErrorType

另请参见 ErrorType

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.