本页内容

QDBusPendingCall Class

QDBusPendingCall 类表示一个待处理的异步调用。更多内容...

头文件: #include <QDBusPendingCall>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus
由以下对象继承:

QDBusPendingCallWatcher

公共函数

QDBusPendingCall(const QDBusPendingCall &other)
(since 6.10) QDBusPendingCall(QDBusPendingCall &&other)
~QDBusPendingCall()
void swap(QDBusPendingCall &other)
QDBusPendingCall &operator=(QDBusPendingCall &&other)
QDBusPendingCall &operator=(const QDBusPendingCall &other)

静态公共成员

QDBusPendingCall fromCompletedCall(const QDBusMessage &msg)
QDBusPendingCall fromError(const QDBusError &error)

详细说明

QDBusPendingCall 对象是对通过 D-Bus 发送但未等待回复的方法调用的引用。QDBusPendingCall 是一种不透明类型,旨在用作待处理回复的句柄。

在大多数程序中,不会直接使用 QDBusPendingCall 类。可以安全地将其替换为基于模板的QDBusPendingReply ,以便访问回复的内容或等待其完成。

QDBusPendingCallWatcher 类允许用户订阅一个信号,该信号会在回复到达或调用超时时发出通知。它还提供了QDBusPendingCallWatcher::waitForFinished()方法,该方法会暂停程序的执行,直到回复到达为止。

注意:如果 创建 QDBusPendingCall 对象的副本,所有信息将在多个副本之间共享。因此,QDBusPendingCall 是一个显式共享的对象,且不提供用于分离副本的方法(因为它们都引用同一个待处理调用)

另请参阅 QDBusPendingReply 和QDBusPendingCallWatcher 。

成员函数文档

QDBusPendingCall::QDBusPendingCall(const QDBusPendingCall &other)

创建other 待处理异步调用的副本。请注意,这两个对象都将引用同一个待处理调用。

[constexpr noexcept default, since 6.10] QDBusPendingCall::QDBusPendingCall(QDBusPendingCall &&other)

将other 移入该对象。

注意: 被移动的对象 other 将处于部分初始化状态,在此状态下,唯一有效的操作是销毁和赋值。

该函数在 Qt 6.10 中引入。

[noexcept] QDBusPendingCall::~QDBusPendingCall()

销毁此QDBusPendingCall 对象的副本。如果该副本同时也是某个待处理异步调用的最后一个副本,则该调用将被取消,且不会再收到任何通知。当响应到达时,将无法访问其内容。

[static] QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg)

根据消息msg 创建一个QDBusPendingCall 对象。该消息必须为QDBusMessage::ErrorMessage 或QDBusMessage::ReplyMessage 类型(即通常代表已完成呼叫的消息)。

此函数适用于需要模拟待处理呼叫,但该呼叫实际上已经结束的代码。

另请参阅 fromError()。

[static] QDBusPendingCall QDBusPendingCall::fromError(const QDBusError &error)

根据错误条件error 创建一个QDBusPendingCall 对象。生成的待处理调用对象将处于“已完成”状态,且QDBusPendingReply<Types...>::isError() 将返回 true。

另请参阅 fromCompletedCall()。

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

将此待处理的调用实例与other 进行交换。此操作速度极快,且绝不会失败。

[noexcept] QDBusPendingCall &QDBusPendingCall::operator=(QDBusPendingCall &&other)

将other 移动并赋值给此QDBusPendingCall 。

注意: 被移动的对象 other 将处于一种部分构成的状态,在此状态下,唯一有效的操作是销毁和赋值新值。

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

创建other 待处理异步调用的副本,并释放对先前引用该调用的引用。请注意,调用此函数后,这两个对象将都指向同一个待处理调用。

如果该对象包含对某个待处理异步调用的最后一个引用,则该调用将被取消,且不会再收到任何通知。当响应到达时,将无法访问其内容。

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