En esta página

QDBusPendingCallWatcher Class

La clase `QDBusPendingCallWatcher` ofrece una forma cómoda de esperar respuestas asíncronas. Más información...

Encabezado: #include <QDBusPendingCallWatcher>
CMake: find_package(Qt6 REQUIRED COMPONENTS DBus)
target_link_libraries(mytarget PRIVATE Qt6::DBus)
qmake: QT += dbus
Heredado de: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);

Ten en cuenta que no es necesario conservar el objeto QDBusPendingCall original, ya que QDBusPendingCallWatcher también hereda de esa clase.

La ranura a la que se conecta 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();
}

Fíjate en el uso de ` QDBusPendingReply ` para validar los tipos de los argumentos de la respuesta. Si la respuesta no contuviera exactamente dos argumentos (una cadena y un ` QByteArray`), ` QDBusPendingReply::isError()` devolverá `true`.

Véase también QDBusPendingReply.

Documentación de funciones de miembro

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

Crea un objeto `QDBusPendingCallWatcher` para supervisar las respuestas de la llamada asíncrona pendiente ` call ` y establece como padre de este objeto ` parent`.

[virtual noexcept] QDBusPendingCallWatcher::~QDBusPendingCallWatcher()

Destruye este objeto. Si este objeto ` QDBusPendingCallWatcher ` era la última referencia a la llamada pendiente sin finalizar, la llamada se cancelará.

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

Esta señal se emite cuando la llamada pendiente ha finalizado y la respuesta está disponible. El parámetro ` self ` es un puntero al propio objeto, que se pasa por comodidad 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 finalizado su procesamiento y se ha recibido la respuesta.

Ten en cuenta que esta función solo cambia de estado si se llama a waitForFinished() o si se produce un evento D-Bus externo, lo que, por lo general, solo 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 del hilo que realiza la llamada hasta que se reciba y se procese la respuesta. Una vez que esta función devuelva un valor, la función isFinished() debería devolver «true», lo que indica 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.