QDBusError Class
QDBusError 类表示从 D-Bus 总线或总线中的远程应用程序接收到的错误。更多内容...
| 头文件: | #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++ 的异常抛出机制,因此您将在返回响应中收到 QDBusError 对象(参见QDBusReply::error())。
QDBusError 对象用于检查从总线和远程应用程序接收到的错误名称和消息。当从 D-Bus 调用时,您不应自行创建此类对象来指示错误情况:而应使用QDBusMessage::createError() 和QDBusConnection::send()。
另请参阅 QDBusConnection::send()、QDBusMessage 以及QDBusReply 。
成员类型文档
enum QDBusError::ErrorType
为了便于验证由 D-Bus 实现以及总线守护进程本身生成的最常见的 D-Bus 错误,可以将QDBusError 与一组预定义值进行比较:
| 常量 | 常量 | 描述 |
|---|---|---|
QDBusError::NoError | 0 | QDBusError 无效(即调用成功) |
QDBusError::Other | 1 | QDBusError 包含非已知错误之一 |
QDBusError::Failed | 2 | 调用失败(org.freedesktop.DBus.Error.Failed ) |
QDBusError::NoMemory | 3 | 内存不足(org.freedesktop.DBus.Error.NoMemory ) |
QDBusError::ServiceUnknown | 4 | 被调用的服务未知(org.freedesktop.DBus.Error.ServiceUnknown ) |
QDBusError::NoReply | 5 | 被调用方法未在指定的超时时间内响应 (org.freedesktop.DBus.Error.NoReply) |
QDBusError::BadAddress | 6 | 给定的地址无效(org.freedesktop.DBus.Error.BadAddress ) |
QDBusError::NotSupported | 7 | 不支持该调用/操作(org.freedesktop.DBus.Error.NotSupported ) |
QDBusError::LimitsExceeded | 8 | 分配给此进程/调用/连接的限制超出了预定义的值(org.freedesktop.DBus.Error.LimitsExceeded ) |
QDBusError::AccessDenied | 9 | 该调用/操作试图访问其无权访问的资源 (org.freedesktop.DBus.Error.AccessDenied) |
QDBusError::NoServer | 10 | 文档中未说明此功能的用途(org.freedesktop.DBus.Error.NoServer ) |
QDBusError::Timeout | 11 | 文档中未说明此项的用途或使用方法(org.freedesktop.DBus.Error.Timeout) |
QDBusError::NoNetwork | 12 | 文档中未说明此功能的用途(org.freedesktop.DBus.Error.NoNetwork ) |
QDBusError::AddressInUse | 13 | QDBusServer 尝试绑定到一个已被占用的地址(org.freedesktop.DBus.Error.AddressInUse ) |
QDBusError::Disconnected | 14 | 该调用/进程/消息是在QDBusConnection 断开连接后发送的 (org.freedesktop.DBus.Error.Disconnected) |
QDBusError::InvalidArgs | 15 | 传递给此调用/操作的参数无效(org.freedesktop.DBus.Error.InvalidArgs ) |
QDBusError::UnknownMethod | 16 | 在该对象/接口中未找到具有给定参数的调用方法(org.freedesktop.DBus.Error.UnknownMethod ) |
QDBusError::TimedOut | 17 | 文档中未提及……(org.freedesktop.DBus.Error.TimedOut ) |
QDBusError::InvalidSignature | 18 | 类型签名无效或不兼容 (org.freedesktop.DBus.Error.InvalidSignature) |
QDBusError::UnknownInterface | 19 | 此对象中未定义该接口 (org.freedesktop.DBus.Error.UnknownInterface) |
QDBusError::UnknownObject | 20 | 对象路径指向一个不存在的对象(org.freedesktop.DBus.Error.UnknownObject ) |
QDBusError::UnknownProperty | 21 | 该属性在此接口中不存在 (org.freedesktop.DBus.Error.UnknownProperty) |
QDBusError::PropertyReadOnly | 22 | 属性设置失败,因为该属性为只读(org.freedesktop.DBus.Error.PropertyReadOnly ) |
QDBusError::InternalError | 23 | 发生内部错误 |
QDBusError::InvalidObjectPath | 25 | 提供的对象路径无效。 |
QDBusError::InvalidService | 24 | 请求的服务无效。 |
QDBusError::InvalidMember | 27 | 该成员无效。 |
QDBusError::InvalidInterface | 26 | 接口无效。 |
成员函数文档
[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 。
© 2026 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.