<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Do not process QTimer slots while waiting for network response]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have my object, subclass of QObject in a seperate thread.<br />
This object uses QNetworkAccessManager to get data from remote server.</p>
<p dir="auto">This is how my code looks like:</p>
<pre><code>  auto reply = networkAccessManager.get(myRequest);
  QEventLoop loop;
  connect(reply, &amp;QNetworkReply::finished, &amp;loop, &amp;QEventLoop::quit);
  loop.exec(QEventLoop::ExcludeSocketNotifiers);
  doSomethngWithData(reply);
</code></pre>
<p dir="auto">But to make things more complicated, my class also contains a QTimer. And I don't want to process timeout events while waiting for data. I don't know how to do that.</p>
<p dir="auto">I hoped QEventLoop::ExcludeSocketNotifiers would postpone timer's slot execution until after the data is loaded and processed, but it doesn't work that way.</p>
<p dir="auto">The only solution I'm thinking about is to have a boolean isLoadingData variable and a queue for timer events, store them there, and process them afterward.</p>
<p dir="auto">Is there a better way?</p>
]]></description><link>https://forum.qt.io/topic/158222/do-not-process-qtimer-slots-while-waiting-for-network-response</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 02:21:10 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/158222.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 14 Aug 2024 18:03:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Do not process QTimer slots while waiting for network response on Thu, 15 Aug 2024 01:47:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tarae">@<bdi>Tarae</bdi></a></p>
<p dir="auto">Hi,</p>
<p dir="auto">what about this?</p>
<pre><code>  auto reply = networkAccessManager.get(myRequest);
  const QSignalBlocker blocker(yourTimer);
  connect(&amp;networkAccessManager, &amp;QNetworkAccessManager::finished, this, [=](QNetworkReply *reply){
      // blocker.unblock(); // maybe not even needed
      doSomethngWithData(reply);
  });
</code></pre>
]]></description><link>https://forum.qt.io/post/807363</link><guid isPermaLink="true">https://forum.qt.io/post/807363</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 15 Aug 2024 01:47:53 GMT</pubDate></item><item><title><![CDATA[Reply to Do not process QTimer slots while waiting for network response on Wed, 14 Aug 2024 19:26:10 GMT]]></title><description><![CDATA[<p dir="auto">Hi, thank you for your idea. That would probably work. But in my case, it is complicated. There are actually like 5 timers, some of them active and some not. Storing the active/inactive state and remaining time for each, then restoring them... I would probably create a timer subclass <code>PausableTimer</code>, but it's still complicated. If there were an easier way, I would prefer it.</p>
]]></description><link>https://forum.qt.io/post/807356</link><guid isPermaLink="true">https://forum.qt.io/post/807356</guid><dc:creator><![CDATA[Tarae]]></dc:creator><pubDate>Wed, 14 Aug 2024 19:26:10 GMT</pubDate></item><item><title><![CDATA[Reply to Do not process QTimer slots while waiting for network response on Wed, 14 Aug 2024 18:36:29 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Why not stop the timer when starting the request and start it again when it's done processing ?</p>
]]></description><link>https://forum.qt.io/post/807350</link><guid isPermaLink="true">https://forum.qt.io/post/807350</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 14 Aug 2024 18:36:29 GMT</pubDate></item></channel></rss>