<?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[Looping inside console application]]></title><description><![CDATA[<p dir="auto">Hello All,</p>
<p dir="auto">I wonder if somebody can advice what the best practice is to loop inside a Qt console application.<br />
My test example below should:</p>
<ol>
<li>send request over network</li>
<li>handle response</li>
<li>if response is "quit" leave, else go to point 1</li>
</ol>
<p dir="auto">Here the example code:</p>
<pre><code>Test::Test() : network(this) {
  QObject::connect(network, SIGNAL(handleResponse(const QString &amp;)),
      this, SLOT(slotHandleResponse(const QString &amp;)));
}

void Test::run() {
  network-&gt;sendRequest();
}

void Test::slotHandleResponse(const QString response) {
  if(response == "quit") {
    emit finished();
  } else {
    // send next request
    run();
  }
}

int main(int argc, char **argv) {
  QCoreApplication app(argc, argv);
  Test test();
  QObject::connect(&amp;test, SIGNAL(finished()), &amp;app, SLOT(quit()));
  QTimer::singleShot(0, &amp;test, SLOT(run()));
  return(app.exec());
}
</code></pre>
<p dir="auto">Is it ok to call run() from within slotHandleResponse() again and again until I get "quit" ? Or should I use QTimer::singleShot() again ? Or something else ?</p>
<p dir="auto">Thanks for any help</p>
]]></description><link>https://forum.qt.io/topic/85166/looping-inside-console-application</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Apr 2026 16:04:42 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/85166.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 19 Nov 2017 16:07:33 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Looping inside console application on Mon, 20 Nov 2017 18:56:22 GMT]]></title><description><![CDATA[<p dir="auto">Hello SGaist,</p>
<p dir="auto">thanks for the hint, this is exactly what I was looking for.</p>
]]></description><link>https://forum.qt.io/post/427334</link><guid isPermaLink="true">https://forum.qt.io/post/427334</guid><dc:creator><![CDATA[sbielmann]]></dc:creator><pubDate>Mon, 20 Nov 2017 18:56:22 GMT</pubDate></item><item><title><![CDATA[Reply to Looping inside console application on Sun, 19 Nov 2017 21:40:10 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">What about using a <a href="http://doc.qt.io/qt-5/qstatemachine.html" target="_blank" rel="noopener noreferrer nofollow ugc">QStateMachine</a> ? You'd need a custom transition to handle the "end/restart" use case.</p>
]]></description><link>https://forum.qt.io/post/427139</link><guid isPermaLink="true">https://forum.qt.io/post/427139</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 19 Nov 2017 21:40:10 GMT</pubDate></item></channel></rss>