QDBusPendingCallWatcher Class
A classe QDBusPendingCallWatcher oferece uma maneira prática de aguardar respostas assíncronas. Mais...
| Cabeçalho: | #include <QDBusPendingCallWatcher> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS DBus) target_link_libraries(mytarget PRIVATE Qt6::DBus) |
| qmake: | QT += dbus |
| Herdado de: | QObject e QDBusPendingCall |
Funções públicas
| QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr) | |
| virtual | ~QDBusPendingCallWatcher() |
| bool | isFinished() const |
| void | waitForFinished() |
Sinais
| void | finished(QDBusPendingCallWatcher *self = nullptr) |
Descrição detalhada
O QDBusPendingCallWatcher fornece o sinal finished(), que será emitido quando uma resposta chegar.
Geralmente é usado como no exemplo a seguir:
QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this,
&DBus_PendingCall_Interface::callFinishedSlot);Observe que não é necessário manter o objeto QDBusPendingCall original, já que o QDBusPendingCallWatcher também herda dessa classe.
O slot conectado pelo código acima poderia ser algo semelhante ao seguinte:
void DBus_PendingCall_Interface::callFinishedSlot(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<QString, QByteArray> reply = *call;
if (reply.isError()) {
showError();
} else {
QString text = reply.argumentAt<0>();
QByteArray data = reply.argumentAt<1>();
showReply(text, data);
}
call->deleteLater();
}Observe o uso de ` QDBusPendingReply ` para validar os tipos dos argumentos na resposta. Se a resposta não contiver exatamente dois argumentos (uma string e um ` QByteArray`), ` QDBusPendingReply::isError()` retornará `true`.
Veja também QDBusPendingReply.
Documentação da função de membro
[explicit] QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)
Cria um objeto `QDBusPendingCallWatcher` para monitorar respostas na chamada pendente assíncrona ` call ` e define o pai desse objeto como ` parent`.
[virtual noexcept] QDBusPendingCallWatcher::~QDBusPendingCallWatcher()
Destrói este objeto. Se este objeto ` QDBusPendingCallWatcher ` for a última referência à chamada pendente e não concluída, a chamada será cancelada.
[signal] void QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher *self = nullptr)
Esse sinal é emitido quando a chamada pendente é concluída e sua resposta está disponível. O parâmetro ` self ` é um ponteiro para o próprio objeto, passado por conveniência para que o slot possa acessar as propriedades e determinar o conteúdo da resposta.
bool QDBusPendingCallWatcher::isFinished() const
Retorna ` true ` se a chamada pendente tiver concluído o processamento e a resposta tiver sido recebida.
Observe que esta função só altera o estado se você chamar waitForFinished() ou se ocorrer um evento D-Bus externo, o que, em geral, só acontece se você retornar à execução do ciclo de eventos.
Veja também QDBusPendingReply::isFinished().
void QDBusPendingCallWatcher::waitForFinished()
Suspende a execução da thread chamadora até que a resposta seja recebida e processada. Após o retorno desta função, ` isFinished()` deve retornar `true`, indicando que o conteúdo da resposta está pronto para ser processado.
Veja também QDBusPendingReply::waitForFinished().
© 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.