title: Qt test how to stop execution when a signal is emitted
body: <p>I am currently testing a Qt application. I have to build a test to check the correct input and output of csv files.</p>
  
  <p>Problem:</p>
  
  <p>The data is being read asynchronously and my test program is ending before the data is loaded and this is the output i get.</p>
  
  <pre><code>QFATAL: Received signal 11
  FAIL! : Received a fatal error
  </code></pre>
  
  <p>Program flow: </p>
  
  <p>There is a class AsyncLoader that loads the data. After the data read is finished, it emits a completed() signal.</p>
  
  <p>So, I modified the test program to include an <a href="http://doc.qt.io/qt-4.8/qeventloop.html" rel="nofollow">QEventLoop</a>. The code is shown below</p>
  
  <pre><code>#pragma once
  
  #include &lt;QEventLoop&gt;
  #include &lt;QSignalSpy&gt;
  #include "asyncloader.h"
  #include "alphaevent.h"
  #include "mainwindow.h"
  #include &lt;QtTest/QtTest&gt;
  
  class Test1: public QObject
  {
      Q_OBJECT
  
  private slots:
      void initTestCase();
      void mainWindowTester();
      void cleanupTestCase();
  };
  
  void Test1::initTestCase()
  {
    qDebug()&lt;&lt;"hello";
  }
  
  void Test1::mainWindowTester()
  {    
    AlphaEvent *fs1 = new AlphaEvent(this);
  
    fs1-&gt;setOperation(AlphaEvent::FileOpen);
    fs1-&gt;setPath(QString("/home/user/PC5.csv"));
  
    MainWindow *mw1 = new MainWindow();    
  
    QEventLoop loop;
    loop.connect(mw1, SIGNAL(completed(FileEvent*)), SLOT(quit()));
    mw1-&gt;dataSetIORequest(fs1);
    loop.exec();
  
    int pqr = mw1-&gt;_package-&gt;dataSet-&gt;rowCount();
    int pqr1 = mw1-&gt;_package-&gt;dataSet-&gt;columnCount();
  
    qDebug() &lt;&lt; "pqr== "&lt;&lt; pqr;
    qDebug() &lt;&lt; "-----------------------------------------------";
    QVERIFY(pqr==5);
  
  void Test1::cleanupTestCase()
  {
  }    
  
  QTEST_MAIN(Test1)
  #include "test1.moc"
  </code></pre>
  
  <p>But with this, I get a "subprocess error: <a href="http://doc.qt.io/qt-5/qprocess.html#ProcessError-enum" rel="nofollow">FailedToStart</a>"</p>
  
  <p>Is there a way to test an asynchronous unit?</p>
  
  <p>I am using Qt version 5.4.2, QMake version 3.0</p>