<?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[ending thread at end of app]]></title><description><![CDATA[<p dir="auto">Hi all -</p>
<p dir="auto">I've seen some other postings on this, but none are quite focused on my issue.</p>
<p dir="auto">Recently, when I close an app by pressing the "X" in the upper right corner of my main widget (this is Window 10), I started getting an error message:</p>
<pre><code>QThread: Destroyed while thread is still running
</code></pre>
<p dir="auto">If I'm in the debugger, it really throws a shoe, asking me (twice) if I want to debug the process, etc.</p>
<p dir="auto">I'm not entirely sure what's going on here. Here's some of my main code:</p>
<pre><code>    QApplication a(argc, argv);
    ModelDevice modelDevices(nullptr);
   QThread thread(&amp;a);
    
    worker = new Worker(&amp;modelDevices);
    worker-&gt;moveToThread(&amp;thread);

    QObject::connect(&amp;widget, &amp;Widget::quitButtonPushed, &amp;thread, &amp;QThread::exit);
    QObject::connect(&amp;thread, &amp;QThread::finished, &amp;a, &amp;QApplication::quit);
    QObject::connect(&amp;thread, &amp;QThread::finished, worker, &amp;Worker::deleteLater);
</code></pre>
<p dir="auto">I had the idea of having the widget destructor signal the thread to quit:</p>
<pre><code>// this doesn't compile
QObject::connect(&amp;widget, &amp;Widget::sendTerminate, &amp;thread, QThread::quit);
</code></pre>
<p dir="auto">But I get a warning about a call to non-static member function without an object argument.</p>
<p dir="auto">So:</p>
<ol>
<li>would this be the right way to do this if I can get that line fixed?</li>
<li>what's wrong with that attempted connection? It seems to me that thread is the object, so I don't understand the error message.</li>
</ol>
<p dir="auto">Thanks...</p>
]]></description><link>https://forum.qt.io/topic/120103/ending-thread-at-end-of-app</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 23:48:51 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/120103.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 Oct 2020 01:27:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ending thread at end of app on Tue, 20 Oct 2020 02:26:16 GMT]]></title><description><![CDATA[<p dir="auto">Beautiful...thanks, Bonnie. (The worker doesn't block; it's really just a bunch of signals and slots connected to the widget.)</p>
]]></description><link>https://forum.qt.io/post/623054</link><guid isPermaLink="true">https://forum.qt.io/post/623054</guid><dc:creator><![CDATA[mzimmers]]></dc:creator><pubDate>Tue, 20 Oct 2020 02:26:16 GMT</pubDate></item><item><title><![CDATA[Reply to ending thread at end of app on Tue, 20 Oct 2020 02:08:22 GMT]]></title><description><![CDATA[<p dir="auto">If your QThread is only in main.cpp, the normal way is</p>
<pre><code>int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ...
    int code = a.exec();
    thread.quit();//do something to quit the thread, this depends on how your Worker is working. If it is blocking, you need to find a way to tell it to stop
    thread.wait();//wait the thread to finish
    return code;
}

</code></pre>
]]></description><link>https://forum.qt.io/post/623049</link><guid isPermaLink="true">https://forum.qt.io/post/623049</guid><dc:creator><![CDATA[Bonnie]]></dc:creator><pubDate>Tue, 20 Oct 2020 02:08:22 GMT</pubDate></item></channel></rss>