From 65da4c717517fdb2066a7887f64b63fd9e4d3bd1 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Sun, 14 Dec 2025 10:56:08 +0300
Subject: Implicitly process messages that arrived while awaiting for reply

This changes the behaviour of TQT_DBusConnection::sendWithReply():
before the patch in case some message arrives while awaiting for a
reply in dbus_connection_send_with_reply_and_block(), they were enqueued
and won't be processed until some other message kicks it on or a user
explicitly called scheduleDispatch() or dispatch().

This commit adds an implicit call to scheduleDispatch() to avoid
unexpected delays in processing incoming messages.

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 src/tqdbusconnection.cpp | 2 ++
 src/tqdbusconnection.h   | 5 +++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/tqdbusconnection.cpp b/src/tqdbusconnection.cpp
index f61f2f2..76be5be 100644
--- a/src/tqdbusconnection.cpp
+++ b/src/tqdbusconnection.cpp
@@ -297,6 +297,8 @@ TQT_DBusMessage TQT_DBusConnection::sendWithReply(const TQT_DBusMessage &message
     ret.d->error.setDBUSError(dbus_error_set);
     if (error) error->setDBUSError(dbus_error_set);
 
+    d->scheduleDispatch();
+
     return ret;
 }
 
diff --git a/src/tqdbusconnection.h b/src/tqdbusconnection.h
index 20e04c4..a1696a9 100644
--- a/src/tqdbusconnection.h
+++ b/src/tqdbusconnection.h
@@ -374,8 +374,9 @@ public:
      *
      * Sends a message composed through the TQT_DBusMessage API to the bus.
      * It then blocks and waits until the associated reply is received.
-     * Any message received in between is stored and can be processed
-     * by calling dispatch() or scheduleDispatch()
+     * Any message received in between is stored and will be processed when
+     * control flow reaches event loop for the next time. Alternatively it can
+     * be processed earlier by calling dispatch().
      *
      * @note for doing method calls it is more convenient to use TQT_DBusProxy,
      *       see TQT_DBusProxy::sendWithReply()
-- 
cgit v1.2.3

