En esta página

QDBusPendingCallWatcher Class

La clase QDBusPendingCallWatcher proporciona una forma cómoda de esperar respuestas asíncronas. Más...

Cabecera: #include <QDBusPendingCallWatcher>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus
Hereda: QObject y QDBusPendingCall

Funciones públicas

QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)
virtual ~QDBusPendingCallWatcher()
bool isFinished() const
void waitForFinished()

Señales

void finished(QDBusPendingCallWatcher *self = nullptr)

Descripción Detallada

QDBusPendingCallWatcher proporciona la señal finished() que se emitirá cuando llegue una respuesta.

Normalmente se utiliza como en el siguiente ejemplo:

    QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2);
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);

    QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this,
                     &DBus_PendingCall_Interface::callFinishedSlot);

Nótese que no es necesario mantener el objeto original QDBusPendingCall ya que QDBusPendingCallWatcher también hereda de esa clase.

La ranura conectada por el código anterior podría ser algo similar a lo siguiente:

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();
}

Observa el uso de QDBusPendingReply para validar los tipos de argumento en la respuesta. Si la respuesta no contiene exactamente dos argumentos (una cadena y uno QByteArray), QDBusPendingReply::isError() devolverá true.

Véase también QDBusPendingReply.

Documentación de las funciones miembro

[explicit] QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent = nullptr)

Crea un objeto QDBusPendingCallWatcher para vigilar las respuestas en la llamada pendiente asíncrona call y establece el padre de este objeto a parent.

[virtual noexcept] QDBusPendingCallWatcher::~QDBusPendingCallWatcher()

Destruye este objeto. Si este objeto QDBusPendingCallWatcher era la última referencia a la llamada pendiente no finalizada, la llamada se cancelará.

[signal] void QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher *self = nullptr)

Esta señal se emite cuando la llamada pendiente ha finalizado y su respuesta está disponible. El parámetro self es un puntero al propio objeto, pasado por conveniencia para que la ranura pueda acceder a las propiedades y determinar el contenido de la respuesta.

bool QDBusPendingCallWatcher::isFinished() const

Devuelve true si la llamada pendiente ha terminado de procesarse y se ha recibido la respuesta.

Tenga en cuenta que esta función sólo cambia de estado si llama a waitForFinished() o si se produce un evento D-Bus externo, lo que en general sólo ocurre si se vuelve a la ejecución del bucle de eventos.

Véase también QDBusPendingReply::isFinished().

void QDBusPendingCallWatcher::waitForFinished()

Suspende la ejecución de la hebra llamante hasta que se reciba y procese la respuesta. Tras el retorno de esta función, isFinished() debería devolver true, indicando que el contenido de la respuesta está listo para ser procesado.

Véase también 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.