title: Test method with Signals and Slots
body: <p>I have the following two simple methods in a Qt Console Application:</p>
  
  <pre><code>void Webservice::getFile(PostElement el)
  {
    parameter = &amp;el;
    QUrl url(PATH);
    QUrlQuery query;
    query.addQueryItem(el.getParam(), el.getValue());
    url.setQuery(query);
    request.setUrl(url);
    manager-&gt;get(request);
    connect(manager, SIGNAL(finished(QNetworkReply*)), this,
            SLOT(downloadCompleted(QNetworkReply*)));
  }
  
  void Webservice::downloadCompleted(QNetworkReply *reply)
  {
    QByteArray b = reply-&gt;readAll();
    qDebug() &lt;&lt; "Download completed!";
    QFile file("/tmp/" + parameter-&gt;getValue());
    file.open(QIODevice::WriteOnly);
    file.write(b);
    file.close();
    reply-&gt;deleteLater();
  }
  </code></pre>
  
  <p>I created a QTest project to test <code>getFile</code> method.</p>
  
  <pre><code>#include &lt;QtTest&gt;
  #include &lt;QCoreApplication&gt;
  
  // add necessary includes here
  #include "webservice.h"
  
  class WebserviceTest : public QObject
  {
    Q_OBJECT
  
  public:
    WebserviceTest();
    ~WebserviceTest();
  
  private:
    Webservice ws;
  
  private slots:
    void initTestCase();
    void cleanupTestCase();
    void getFile();
  };
  
  WebserviceTest::WebserviceTest()
  {
  
  }
  
  WebserviceTest::~WebserviceTest()
  {
  
  }
  
  void WebserviceTest::initTestCase()
  {
  
  }
  
  void WebserviceTest::cleanupTestCase()
  {
  
  }
  
  void WebserviceTest::getFile()
  {
    PostElement el{"file", "myPic.png"};
    ws.getFile(el); // it should wait for the slot to be executed
  }
  
  QTEST_MAIN(WebserviceTest)
  
  #include "tst_webservicetest.moc"
  </code></pre>
  
  <p>As you can see, it has signals and slots. If I run that one on my original project, I see that <code>downloadCompleted</code> executes without issues (because it is using the Event Loop). But in the test project the slot is not called. I googled and found some examples using QSignalSpy, but at the moment I have not executed the slot successfully. </p>
  
  <p>How to tell my test to "wait" for the slot to be completed?</p>