<?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[create new QApplication in different thread]]></title><description><![CDATA[<p dir="auto">running this very simple code</p>
<pre><code>int main(int argc, char** argv) {
    qDebug() &lt;&lt; "create app 1" &lt;&lt; QThread::currentThreadId();
    QApplication* a = new QApplication(argc, argv);
    qDebug() &lt;&lt; "delete app 1";
    delete a;

    qDebug() &lt;&lt; "create app 2" &lt;&lt; QThread::currentThreadId();
    QApplication* b = new QApplication(argc, argv);
    qDebug() &lt;&lt; "delete app 2";
    delete b;

    auto func = [&amp;] {
        qDebug() &lt;&lt; "create app 3" &lt;&lt; QThread::currentThreadId();
        QApplication* c = new QApplication(argc, argv);
        qDebug() &lt;&lt; "delete app 2";
        delete c;
    };
    std::thread t(func);
    t.join();

    qDebug() &lt;&lt; "done";
    return 0;
}
</code></pre>
<p dir="auto">I get the output</p>
<pre><code>create app 1 0x420c
delete app 1
create app 2 0x420c
delete app 2
create app 3 0x75fc
WARNING: QApplication was not created in the main() thread.
Exception thrown at 0x00007FFE915B7BC9 (Qt6Guid.dll)
</code></pre>
<p dir="auto">Now I do not understand:<br />
I read there can be only one instance of QApplication - Ok I take care of that<br />
I read a QApplication <strong>can</strong> be created on a different thread, which then becomes sort of the application thread<br />
Then why is this example not possible?</p>
<p dir="auto">Qt 6.11.1, Windows 11</p>
]]></description><link>https://forum.qt.io/topic/165015/create-new-qapplication-in-different-thread</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 19:10:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165015.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Aug 2026 11:28:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to create new QApplication in different thread on Sun, 16 Aug 2026 14:27:56 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the clarification. That explains the behavior.</p>
<p dir="auto">The limitation makes sense for my use case (Qt used as a plugin inside a non-Qt application). I had interpreted the documentation to mean that, as long as only one <code>QApplication</code> instance exists at a time, recreating it in a different thread would be supported.</p>
<p dir="auto">Knowing that <code>QGuiApplication</code> leaves behind internal objects tied to the first thread, making cross-thread recreation currently impossible, answers my question. I'll adjust the design accordingly.</p>
<p dir="auto">Thanks for the detailed explanation and the Qt bug reference.</p>
]]></description><link>https://forum.qt.io/post/839740</link><guid isPermaLink="true">https://forum.qt.io/post/839740</guid><dc:creator><![CDATA[TimTom420]]></dc:creator><pubDate>Sun, 16 Aug 2026 14:27:56 GMT</pubDate></item><item><title><![CDATA[Reply to create new QApplication in different thread on Sun, 16 Aug 2026 13:28:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ronel_qtmaster">@<bdi>Ronel_qtmaster</bdi></a> said in <a href="/post/839736">create new QApplication in different thread</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/csab6597">@<bdi>csab6597</bdi></a> this is bad coding . I think it is better to use QProcess as it seems you dont understand the purpose of your QApplication</p>
</blockquote>
<p dir="auto">There are perfectly valid use-cases to destroy a QApplication and recreate it in another thread. For example, when Qt is used to implement a plugin for a non-Qt app.</p>
]]></description><link>https://forum.qt.io/post/839739</link><guid isPermaLink="true">https://forum.qt.io/post/839739</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Sun, 16 Aug 2026 13:28:42 GMT</pubDate></item><item><title><![CDATA[Reply to create new QApplication in different thread on Sun, 16 Aug 2026 13:27:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/csab6597">@<bdi>csab6597</bdi></a> said in <a href="/post/839735">create new QApplication in different thread</a>:</p>
<blockquote>
<p dir="auto">I read a QApplication <strong>can</strong> be created on a different thread, which then becomes sort of the application thread</p>
</blockquote>
<p dir="auto">Yes, that's right.</p>
<p dir="auto">If you <strong>don't</strong> create <code>a</code> and <code>b</code> first, then your <code>c</code> will not produce any warnings and your <code>func</code> thread will be considered the "main thread".</p>
<blockquote>
<p dir="auto">Then why is this example not possible?</p>
</blockquote>
<p dir="auto">This is a current limitation in Qt. <code>QGuiApplication</code> creates some internal QObjects that never get destroyed (here is one example: <a href="https://qt-project.atlassian.net/browse/QTBUG-141714" target="_blank" rel="noopener noreferrer nofollow ugc">https://qt-project.atlassian.net/browse/QTBUG-141714</a>), so it is currently not possible to re-create <code>QGuiApplication</code>/<code>QApplication</code> in a different thread from your first instance.</p>
<p dir="auto">In contrast, your example should work fine if you use <code>QCoreApplication</code>.</p>
]]></description><link>https://forum.qt.io/post/839738</link><guid isPermaLink="true">https://forum.qt.io/post/839738</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Sun, 16 Aug 2026 13:27:11 GMT</pubDate></item><item><title><![CDATA[Reply to create new QApplication in different thread on Sun, 16 Aug 2026 12:10:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/csab6597">@<bdi>csab6597</bdi></a> this is bad coding . I think it is better to use QProcess as it seems you dont understand the purpose of your QApplication</p>
]]></description><link>https://forum.qt.io/post/839736</link><guid isPermaLink="true">https://forum.qt.io/post/839736</guid><dc:creator><![CDATA[Ronel_qtmaster]]></dc:creator><pubDate>Sun, 16 Aug 2026 12:10:14 GMT</pubDate></item></channel></rss>