<?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[QApplication was not created in the main() thread]]></title><description><![CDATA[<p dir="auto">Hello everyone,<br />
Could someone explain why in the following scenario some buggy behavior is present(QTextEdit window is not automatycally updated):</p>
<p dir="auto">@<br />
#include &lt;qapplication.h&gt;<br />
#include &lt;qtextedit.h&gt;<br />
#include &lt;qrunnable.h&gt;<br />
#include &lt;qthread.h&gt;<br />
#include &lt;qthreadpool.h&gt;</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
class GUIinThread : public QRunnable<br />
{<br />
void run()<br />
{<br />
int argc = 1;</p>
<p dir="auto">QByteArray argvStr = QString("").toLatin1();<br />
char* argv = argvStr.data();</p>
<p dir="auto">QApplication a(argc, &amp;argv);</p>
<p dir="auto">QTextEdit textEdit;<br />
textEdit.show();</p>
<p dir="auto">a.exec();<br />
}<br />
};</p>
<p dir="auto">GUIinThread *createGUI = new GUIinThread();<br />
QThreadPool::globalInstance()-&gt;setExpiryTimeout(-1);<br />
QThreadPool::globalInstance()-&gt;start(createGUI);</p>
<p dir="auto">while(true); // prevent main() from return<br />
return 0;-<br />
}@</p>
<p dir="auto">And why is this so important to create QApplication in the main thread?<br />
I'm using Qt5.1.1 under WIn7<br />
Thnaks in advance!</p>
]]></description><link>https://forum.qt.io/topic/34293/qapplication-was-not-created-in-the-main-thread</link><generator>RSS for Node</generator><lastBuildDate>Thu, 20 Aug 2026 05:14:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/34293.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Nov 2013 14:47:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Fri, 15 Nov 2013 14:46:26 GMT]]></title><description><![CDATA[<p dir="auto">You're welcome :) All the best!</p>
<p dir="auto">(I actually found the first link after reading your post, by searching "GUI main thread" in Google)</p>
]]></description><link>https://forum.qt.io/post/204214</link><guid isPermaLink="true">https://forum.qt.io/post/204214</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 15 Nov 2013 14:46:26 GMT</pubDate></item><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Fri, 15 Nov 2013 11:42:59 GMT]]></title><description><![CDATA[<p dir="auto">Thats a bunch of usfefull links you've got  :) (not really too easy to find them on your own)<br />
Ive been stepping into Qt source all morning but was unable to find the difference to QEventDispatcherWin32 if created not on the main thread...<br />
So I guess Im gonna have to go with your suggestion of renaming my main() etc...<br />
Thanks again :)</p>
]]></description><link>https://forum.qt.io/post/204186</link><guid isPermaLink="true">https://forum.qt.io/post/204186</guid><dc:creator><![CDATA[terenty]]></dc:creator><pubDate>Fri, 15 Nov 2013 11:42:59 GMT</pubDate></item><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Fri, 15 Nov 2013 07:17:43 GMT]]></title><description><![CDATA[<p dir="auto">You're welcome. Yea, creating a cross-platform library is hard work. But I think the benefits outweigh the downsides :)</p>
<p dir="auto">Hmm... could you rename your current main() into something else, and just call it from another thread? You can create a new main(), create your GUI, and start a new thread to run the old main().</p>
<p dir="auto">P.S. See <a href="http://doc-snapshot.qt-project.org/qt5-stable/threads-technologies.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc-snapshot.qt-project.org/qt5-stable/threads-technologies.html</a> for a comparison of different ways to use threads in Qt. QRunnable is not suitable for permanent threads.</p>
]]></description><link>https://forum.qt.io/post/204140</link><guid isPermaLink="true">https://forum.qt.io/post/204140</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 15 Nov 2013 07:17:43 GMT</pubDate></item><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Fri, 15 Nov 2013 07:02:45 GMT]]></title><description><![CDATA[<p dir="auto">JKSH,<br />
Thanks, it's finally starting to make sense. That OS X must be a really "fun" thing to deal with... Too bad it has such a frustrating influence on Qt...</p>
<p dir="auto">I have a console app that makes a lot of computation in it's main() and log iteration data to a file, i wanted to log into quickly made fully responsible gui running in parallel to main() so it would be a little change to main() but faced this limitation :(</p>
]]></description><link>https://forum.qt.io/post/204138</link><guid isPermaLink="true">https://forum.qt.io/post/204138</guid><dc:creator><![CDATA[terenty]]></dc:creator><pubDate>Fri, 15 Nov 2013 07:02:45 GMT</pubDate></item><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Fri, 15 Nov 2013 02:41:56 GMT]]></title><description><![CDATA[<p dir="auto">Some platforms restrict GUI interactions to the first thread spawned by a process: <a href="http://www.dribin.org/dave/blog/archives/2009/02/01/main_thread_apis/" target="_blank" rel="noopener noreferrer nofollow ugc">http://www.dribin.org/dave/blog/archives/2009/02/01/main_thread_apis/</a></p>
<p dir="auto">Qt is a cross-platform library, and thus it needs to follow the platforms' rules.</p>
]]></description><link>https://forum.qt.io/post/204126</link><guid isPermaLink="true">https://forum.qt.io/post/204126</guid><dc:creator><![CDATA[JKSH]]></dc:creator><pubDate>Fri, 15 Nov 2013 02:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Thu, 14 Nov 2013 16:18:13 GMT]]></title><description><![CDATA[<p dir="auto">Hi, 1+1=2,<br />
Thanks for the reply, but I still don't get whats so special about main thread and why we can't have another thread devoted to GUI other than main as long as we don't make any cross-thread gui interactions?</p>
]]></description><link>https://forum.qt.io/post/204074</link><guid isPermaLink="true">https://forum.qt.io/post/204074</guid><dc:creator><![CDATA[terenty]]></dc:creator><pubDate>Thu, 14 Nov 2013 16:18:13 GMT</pubDate></item><item><title><![CDATA[Reply to QApplication was not created in the main() thread on Thu, 14 Nov 2013 15:47:51 GMT]]></title><description><![CDATA[<p dir="auto">Hi, QApplication and all other QWidget can only be used in main thread.</p>
<p dir="auto"><a href="http://qt-project.org/doc/qt-5.1/qtcore/threads-qobject.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.1/qtcore/threads-qobject.html</a></p>
]]></description><link>https://forum.qt.io/post/204072</link><guid isPermaLink="true">https://forum.qt.io/post/204072</guid><dc:creator><![CDATA[dbzhang800]]></dc:creator><pubDate>Thu, 14 Nov 2013 15:47:51 GMT</pubDate></item></channel></rss>