<?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[[SOLVED] Console application with thread: It is not closed]]></title><description><![CDATA[<p dir="auto">I'm coding a console application that runs a QThread for connections and at same time, waits for user inputs by keyboard.</p>
<p dir="auto">My problem is that then of read what user's write, I send a signal to close the application and nothing happens. Is the first console appliation using Qt and I'm not sure if I'm following what Qt waits. Here is the code:</p>
<p dir="auto">@int main(int argc, char *argv[])<br />
{<br />
QCoreApplication app(argc, argv);<br />
CommandLineApp cmd;</p>
<pre><code>QObject::connect(&amp;cmd, SIGNAL(quitApp()), &amp;app, SLOT(quit()));

cmd.exec&amp;#40;&amp;#41;;

return app.exec(&amp;#41;;
</code></pre>
<p dir="auto">}@</p>
<p dir="auto">CommandLineApp.h (Server is a QTcpServer that has a QThread inside):<br />
@#ifndef CommandLineApp_H<br />
#define CommandLineApp_H</p>
<p dir="auto">#include &lt;QObject&gt;<br />
#include "Server.h"<br />
#include &lt;iostream&gt;</p>
<p dir="auto">using namespace std;</p>
<p dir="auto">class CommandLineApp : public QObject<br />
{<br />
Q_OBJECT</p>
<pre><code>signals:
    void quitApp();

public:
    CommandLineApp(QObject *parent = 0);
    void exec&amp;#40;&amp;#41;;

private:
    Server server;
</code></pre>
<p dir="auto">};</p>
<p dir="auto">#endif@</p>
<p dir="auto">CommandLineApp.cpp:<br />
@CommandLineApp::CommandLineApp(QObject *parent) : QObject(parent)<br />
{<br />
server.listen(QHostAddress::LocalHost,5555);<br />
}</p>
<p dir="auto">void CommandLineApp::exec()<br />
{<br />
string option;</p>
<pre><code>QTextStream cout(stdout&amp;#41;;
QTextStream cin(stdin);

cout&lt;&lt;"Set option (help for Help, quit for Quit): ";
cout.flush();
cin&gt;&gt;option;

server.close();

emit quitApp();
</code></pre>
<p dir="auto">}<br />
@</p>
]]></description><link>https://forum.qt.io/topic/30071/solved-console-application-with-thread-it-is-not-closed</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 02:31:17 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/30071.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 Jul 2013 08:27:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Console application with thread: It is not closed on Tue, 30 Jul 2013 11:56:47 GMT]]></title><description><![CDATA[<p dir="auto">Thanks 1+1=2, it also works I've decided to to it to get more clear code.</p>
<p dir="auto">Mark the topic as solved!! :)</p>
]]></description><link>https://forum.qt.io/post/188534</link><guid isPermaLink="true">https://forum.qt.io/post/188534</guid><dc:creator><![CDATA[francescmm]]></dc:creator><pubDate>Tue, 30 Jul 2013 11:56:47 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Console application with thread: It is not closed on Tue, 30 Jul 2013 09:31:44 GMT]]></title><description><![CDATA[<p dir="auto">Hi, IMO,</p>
<p dir="auto">@<br />
return app.exec();<br />
@</p>
<p dir="auto">can be simply replaced with</p>
<p dir="auto">@<br />
return 0;<br />
@</p>
<p dir="auto">As the event loop make non-sense in such case.</p>
]]></description><link>https://forum.qt.io/post/188508</link><guid isPermaLink="true">https://forum.qt.io/post/188508</guid><dc:creator><![CDATA[dbzhang800]]></dc:creator><pubDate>Tue, 30 Jul 2013 09:31:44 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Console application with thread: It is not closed on Tue, 30 Jul 2013 09:24:15 GMT]]></title><description><![CDATA[<p dir="auto">You are welcome.</p>
<p dir="auto">Solution good enough if it works :) Qt is more oriented towards GUI stuff (obviously), command line apps are sometimes a bit tricky.</p>
]]></description><link>https://forum.qt.io/post/188505</link><guid isPermaLink="true">https://forum.qt.io/post/188505</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 30 Jul 2013 09:24:15 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Console application with thread: It is not closed on Tue, 30 Jul 2013 09:20:27 GMT]]></title><description><![CDATA[<p dir="auto">Arg! Thanks a lot!!</p>
<p dir="auto">Sometimes we are looking for complex problems and the problem is basic!</p>
<p dir="auto">Shoddy solution: add a timer with singleShot! :)</p>
]]></description><link>https://forum.qt.io/post/188504</link><guid isPermaLink="true">https://forum.qt.io/post/188504</guid><dc:creator><![CDATA[francescmm]]></dc:creator><pubDate>Tue, 30 Jul 2013 09:20:27 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Console application with thread: It is not closed on Tue, 30 Jul 2013 09:02:42 GMT]]></title><description><![CDATA[<p dir="auto">You emit quitApp() before QCoreApplication enters it's event loop: that is, before signals and slots (and the whole Qt Meta Ojbect System) is able to work.</p>
]]></description><link>https://forum.qt.io/post/188500</link><guid isPermaLink="true">https://forum.qt.io/post/188500</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 30 Jul 2013 09:02:42 GMT</pubDate></item></channel></rss>