<?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[QProcess is blocking UI and destroyed  while app running]]></title><description><![CDATA[<p dir="auto">Hello All,</p>
<p dir="auto">I am facing strange issues with QProcess (Qt 5.12.12) on MacOS and Linux. I am running long process (DFU programming) that takes about 10-15 seconds to complete. I have actually 2 problems:</p>
<ul>
<li>Application UI stops responding while process is running</li>
<li>When the process finishes I get this message</li>
</ul>
<pre><code>(0): QProcess: Destroyed while process ("/Applications/STMicroelectronics/STM32CubeProgrammer/STM32CubeProgrammer.app/Contents/MacOs/bin/STM32_Programmer_CLI") is still running.
</code></pre>
<p dir="auto">The class and thus QProcess instance is destroyed when application exits.</p>
<p dir="auto">I do not know if this is relevant but process is started from timer timeout slot when DFU device is detected, I do not wait for a process to finish, I rely on finished signal. My assumption was that the process runs separately from main window thread and thus is should not block anything. It seems that these issues are not existing on Windows, only on MacOS and Linux.</p>
<p dir="auto">Although these issues are happening, it seems that the process finishes correctly with exist status <code>QProcess::NormalExit</code></p>
<p dir="auto">Releavant pieces of the code:</p>
<pre><code>// header
class DfuProgramming : public QObject
{
    Q_OBJECT
    // ....
private:
   QProcess m_dfuProcess;
   QTimer * m_detectDfuTimer;
}

// source
DfuProgramming::DfuProgramming(QObject *parent) : QObject(parent)
{
    // ...
    connect(&amp;m_dfuProcess, QOverload&lt;int, QProcess::ExitStatus&gt;::of(&amp;QProcess::finished), this, &amp;DfuProgramming::dfuFinishedSlot);
    connect(m_detectDfuTimer, &amp;QTimer::timeout, this, &amp;DfuProgramming::dfuEvent);
    //...
}

void DfuProgramming::dfuEvent()
{
    //...
    m_dfuProcess.start(cmd);
}
</code></pre>
<p dir="auto">What am I doing wrong? Is there any principal issue?</p>
]]></description><link>https://forum.qt.io/topic/145960/qprocess-is-blocking-ui-and-destroyed-while-app-running</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 03:51:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/145960.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 23 Jun 2023 07:47:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QProcess is blocking UI and destroyed  while app running on Mon, 17 Jul 2023 08:56:53 GMT]]></title><description><![CDATA[<p dir="auto">It seems that the problem is somewhere in my app, it is currently not clear where but minimal example I was trying to prepare to share here is working as expected. However full app does not work and I cannot even stop the code to see where it is stuck :-(</p>
<p dir="auto">EDIT: rootcause found - another timer was calling the same executable but with waiting for result. This was causing problem as the second process was waiting for the first to complete (this is limitation of the executable I am running).</p>
]]></description><link>https://forum.qt.io/post/764866</link><guid isPermaLink="true">https://forum.qt.io/post/764866</guid><dc:creator><![CDATA[KejPi]]></dc:creator><pubDate>Mon, 17 Jul 2023 08:56:53 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess is blocking UI and destroyed  while app running on Fri, 23 Jun 2023 11:20:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kejpi">@<bdi>KejPi</bdi></a> said in <a href="/post/762409">QProcess is blocking UI and destroyed while app running</a>:</p>
<blockquote>
<p dir="auto">ctually if I connect to QProcess::readyReadStandardOutput signal, it gets called 3 times before it stops responding</p>
</blockquote>
<p dir="auto">And where does it get stuck there exactly? Inside the Qt code or do you do a blocking read? Please show the code and the backtrace.</p>
]]></description><link>https://forum.qt.io/post/762439</link><guid isPermaLink="true">https://forum.qt.io/post/762439</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 23 Jun 2023 11:20:05 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess is blocking UI and destroyed  while app running on Fri, 23 Jun 2023 11:36:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kejpi">@<bdi>KejPi</bdi></a> said in <a href="/post/762409">QProcess is blocking UI and destroyed while app running</a>:</p>
<blockquote>
<p dir="auto">The QProcess is destroyed on application exit thus there is no reason for "process still running" message.<br />
Ideally I woudl like to continuously capture process stdout using QProcess::readyReadStandardOutput signal thus startDetached() is not suitable.</p>
</blockquote>
<p dir="auto">You cannot have both of these.  If you want to read stdout then as you say you cannot use <code>startDetached()</code>, you must use <code>start()</code>.  And in that case you <em>must</em> terminate the subprocess, by whatever means, before you destroy the <code>QProcess</code>, else you will get that warning message.  "there is no reason for "process still running" message." --- this is what Qt does, you can't alter it.</p>
]]></description><link>https://forum.qt.io/post/762413</link><guid isPermaLink="true">https://forum.qt.io/post/762413</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 23 Jun 2023 11:36:52 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess is blocking UI and destroyed  while app running on Fri, 23 Jun 2023 08:37:53 GMT]]></title><description><![CDATA[<p dir="auto">It does not block during <code>start()</code>. Actually if I connect to <code>QProcess::readyReadStandardOutput</code> signal, it gets called 3 times before it stops responding. The time when application is unresponsive it actually the time when programmer is erasing and programming attached device. During that time I gen no STDOUT from the process altough there is quite a lot of messages from the process.<br />
I have reduced the code so only <code>start()</code> is called and no other method of QProcess is used but the result is the same.<br />
The QProcess is destroyed on application exit thus there is no reason for "process still running" message.</p>
<p dir="auto">Ideally I woudl like to continuously capture process stdout using <code>QProcess::readyReadStandardOutput</code> signal thus <code>startDetached()</code> is not suitable.</p>
]]></description><link>https://forum.qt.io/post/762409</link><guid isPermaLink="true">https://forum.qt.io/post/762409</guid><dc:creator><![CDATA[KejPi]]></dc:creator><pubDate>Fri, 23 Jun 2023 08:37:53 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess is blocking UI and destroyed  while app running on Fri, 23 Jun 2023 07:59:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kejpi">@<bdi>KejPi</bdi></a><br />
As <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> has said.</p>
<p dir="auto">The UI should only block if you call <code>m_dfuProcess.waitForFinished()</code>.  Otherwise if your running process is <em>very</em> intensive it might make the system/desktop "sluggish", but not blocked.</p>
<p dir="auto">If you allow your calling process to exit before the subprocess has finished then you will get the "process is still running" message.  If you intend it to finish then you must make it do so; if you intend it to outlive the calling process then you need to use <code>startDetached()</code>.</p>
]]></description><link>https://forum.qt.io/post/762404</link><guid isPermaLink="true">https://forum.qt.io/post/762404</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 23 Jun 2023 07:59:54 GMT</pubDate></item><item><title><![CDATA[Reply to QProcess is blocking UI and destroyed  while app running on Fri, 23 Jun 2023 07:53:34 GMT]]></title><description><![CDATA[<p dir="auto">Please use a debugger to see where exactly the program is blocking. I doubt it's during start().<br />
Also make sure the timer is a single shot timer so the slot is only called once.</p>
]]></description><link>https://forum.qt.io/post/762403</link><guid isPermaLink="true">https://forum.qt.io/post/762403</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 23 Jun 2023 07:53:34 GMT</pubDate></item></channel></rss>