<?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[How to update the GUI from another thread?]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I have a long-running task (for loop) which I want to run in a seperate QThread (to not block the gui).<br />
In each iteration of the loop I want to send an update to my GUI which will draw a line. How would I do this?<br />
Do I have to use signals to communicate between the MainThread (GUI) and the QThread where I run my computation?</p>
<p dir="auto">Bonus questions: Is it possible to pause the for loop which is inside the seperate QThread via some pause button and then continue again from where it stopped? Is there documentation for this?</p>
]]></description><link>https://forum.qt.io/topic/137062/how-to-update-the-gui-from-another-thread</link><generator>RSS for Node</generator><lastBuildDate>Wed, 01 Jul 2026 18:34:38 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/137062.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 07 Jun 2022 18:09:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to update the GUI from another thread? on Thu, 09 Jun 2022 07:21:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/holigui">@<bdi>HoliGui</bdi></a> said in <a href="/post/716784">How to update the GUI from another thread?</a>:</p>
<blockquote>
<p dir="auto">Thank you this looks really promising. Do you have a suggestion how to decouple GUI logic from business logic?<br />
I tought about implementing an observer/Eventlistener pattern to communicate with the GUI.</p>
</blockquote>
<p dir="auto">Qt's signals and slots already is some sort of observer pattern: The observer will register its slot with the appropriate signals. No need to reinvent the wheel here. Your business logic would just have a signals saying "this has changed" and the GUI logic would take that information (in a slot) and decide how to display it.</p>
<p dir="auto">The problem of executing GUI code in a different thread occurred for me over and over again. You can queue function calls using <code>QMetaObject::invokeMethod(qGuiApp, ...)</code>. Most easily just put in a lambda for <code>'...'</code>. I wrote a little helper library for this: <a href="https://github.com/SimonSchroeder/QtThreadHelper" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/SimonSchroeder/QtThreadHelper</a> . You can just use <code>guiThread(...)</code> to execute any function inside the GUI thread. It is a single header library (requires C++17).</p>
]]></description><link>https://forum.qt.io/post/716978</link><guid isPermaLink="true">https://forum.qt.io/post/716978</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Thu, 09 Jun 2022 07:21:25 GMT</pubDate></item><item><title><![CDATA[Reply to How to update the GUI from another thread? on Wed, 08 Jun 2022 17:39:30 GMT]]></title><description><![CDATA[<p dir="auto">In the case of the example the decoupling is already done.</p>
<p dir="auto">Your business logic should go in a class (or several depending on it) and then you can simply use signals and slots to transmit your data between both. Or use the model view approach.</p>
<p dir="auto">It really depends on what your business logic does and what kind of data it generates that shall be shown on the UI.</p>
]]></description><link>https://forum.qt.io/post/716936</link><guid isPermaLink="true">https://forum.qt.io/post/716936</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 08 Jun 2022 17:39:30 GMT</pubDate></item><item><title><![CDATA[Reply to How to update the GUI from another thread? on Tue, 07 Jun 2022 19:12:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Thank you this looks really promising. Do you have a suggestion how to decouple GUI logic from business logic?<br />
I tought about implementing an observer/Eventlistener pattern to communicate with the GUI.</p>
]]></description><link>https://forum.qt.io/post/716784</link><guid isPermaLink="true">https://forum.qt.io/post/716784</guid><dc:creator><![CDATA[HoliGui]]></dc:creator><pubDate>Tue, 07 Jun 2022 19:12:46 GMT</pubDate></item><item><title><![CDATA[Reply to How to update the GUI from another thread? on Tue, 07 Jun 2022 18:18:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/holigui">@<bdi>HoliGui</bdi></a> said in <a href="/post/716773">How to update the GUI from another thread?</a>:</p>
<blockquote>
<p dir="auto">Do I have to use signals to communicate between the MainThread (GUI) and the QThread where I run my computation?</p>
</blockquote>
<p dir="auto">Yep :)</p>
<blockquote>
<p dir="auto">Bonus questions: Is it possible to pause the for loop which is inside the seperate QThread via some pause button and then continue again from where it stopped?</p>
</blockquote>
<p dir="auto"><code>QThread</code>s do not natively support "pausing".  You might achieve this with signals &amp; slots too.  You will have to write the link to a UI "Pause" button yourself.</p>
]]></description><link>https://forum.qt.io/post/716776</link><guid isPermaLink="true">https://forum.qt.io/post/716776</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 07 Jun 2022 18:18:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to update the GUI from another thread? on Tue, 07 Jun 2022 18:16:01 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">See the <a href="https://doc.qt.io/qt-5/qtcore-threads-mandelbrot-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">Mandelbrot example</a> for a possible implementation.</p>
<p dir="auto">As for stopping and restarting the loop, sure you can, a way to do it also shown in that example. There might be others depending on your needs though.</p>
]]></description><link>https://forum.qt.io/post/716775</link><guid isPermaLink="true">https://forum.qt.io/post/716775</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 07 Jun 2022 18:16:01 GMT</pubDate></item></channel></rss>