title: What exactly happens with QTimer start function?
body: <p>I have the following code:</p>
  
  <p><strong>mytimer.cpp</strong></p>
  
  <pre><code>#include "mytimer.h"
  #include &lt;QtCore&gt;
  MyTimer::MyTimer()
  {
      timer = new QTimer(this);
      connect(timer,SIGNAL(timeout()),this,SLOT(mySlot()));
      timer-&gt;start(1000);    
  }
  
  void MyTimer::mySlot()
  {
      qDebug()&lt;&lt;"timer executed";
  
  }
  </code></pre>
  
  <p>and in the <strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include "mytimer.h"
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      MyTimer mtimer;
      qDebug()&lt;&lt;"DONE";
  
      return a.exec();
  }
  </code></pre>
  
  <p>Now the output comes as:</p>
  
  <pre><code>DONE
  timer executed
  timer executed
  ...
  ...
  ...
  ...
  infinite sequence
  </code></pre>
  
  <p>I am really confused by this. How is that we are done with our main function and still the code for the <code>SLOT mySlot()</code> is getting executed?</p>
  
  <p>What are the important aspects to this? that I need to understand?</p>
  
  <p>Also what changes occurs when I modify <strong>mytimer.cpp</strong> MyTimer() to:</p>
  
  <pre><code>MyTimer::MyTimer()
  {
      timer = new QTimer(this);
      QEventLoop eventloop;
      connect(timer,SIGNAL(timeout()),this,SLOT(mySlot()));
      connect(timer,SIGNAL(timeout()),&amp;eventloop,SLOT(quit()));
      timer-&gt;start(1000);
      eventloop.exec();
  }
  </code></pre>
  
  <p>There is one <strong>timer executed</strong> just before <strong>DONE</strong> is printed. To Be specific the output now becomes:</p>
  
  <pre><code>timer executed
  DONE
  timer executed
  timer executed
  ...
  ...
  ...
  ...
  infinite sequence
  </code></pre>
  
  <p>What caused that separate <strong>timer executed</strong> to appear above the <strong>DONE</strong>?</p>