title: Qt: deadlock after calling QEventLoop::exec
body: <p>I have a rather simple application that seems to deadlock under certain conditions when I invoke QEventLoop::exec. The application calls this function in two scenarios:</p>
  
  <ul>
  <li>when certain data arrives on the socket</li>
  <li>upon a timer event</li>
  </ul>
  
  <p>in both cases it is used in the following context (just an http query, nothing special really):</p>
  
  <pre><code>QNetworkReply::NetworkError HttpGetMessagesStrategy::syncHttp(const QUrl url, QByteArray &amp;dst) const
  {
      QNetworkRequest request(url);
      request.setRawHeader("Cache-Control", "no-cache");
  
      QNetworkAccessManager mgr;
      QEventLoop eventLoop;
      QObject::connect(&amp;mgr, SIGNAL(finished(QNetworkReply *)), &amp;eventLoop, SLOT(quit()));
      QNetworkReply *reply = mgr.get(request);
      if (reply == NULL) {
          return QNetworkReply::UnknownNetworkError;
      }
  
      eventLoop.exec();
  
      QNetworkReply::NetworkError error = reply-&gt;error();
      if (error == QNetworkReply::NoError) {
          dst += reply-&gt;readAll();
      }
      delete reply;
  
      return error;
  }
  </code></pre>
  
  <p>Here's what happens when it tries to call it:</p>
  
  <pre><code>...    
  #56 0x0000003404b57cdc in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
  #57 0x0000003404b804a2 in ?? () from /usr/lib64/libQtCore.so.4
  #58 0x0000003404b7d928 in ?? () from /usr/lib64/libQtCore.so.4
  #59 0x00000033fba38f0e in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
  #60 0x00000033fba3c938 in ?? () from /lib64/libglib-2.0.so.0
  #61 0x00000033fba3ca3a in g_main_context_iteration () from /lib64/libglib-2.0.so.0
  #62 0x0000003404b7d5f3 in QEventDispatcherGlib::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQtCore.so.4
  #63 0x0000003404b56722 in QEventLoop::processEvents(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQtCore.so.4
  #64 0x0000003404b569ec in QEventLoop::exec(QFlags&lt;QEventLoop::ProcessEventsFlag&gt;) () from /usr/lib64/libQtCore.so.4
  #65 0x00007f41c1b4eec7 in HttpGetMessagesStrategy::syncHttp (this=&lt;value optimized out&gt;, url=&lt;value optimized out&gt;, dst=...) at HttpGetMessagesStrategy.cpp:49
  #70 0x000000000040e57c in DevicePlugin::timerEvent (this=0x1267390, event=0x7fff902bb5f0) at DevicePlugin.cpp:250
  #71 0x0000003404b6698e in QObject::event(QEvent*) () from /usr/lib64/libQtCore.so.4
  #72 0x0000003404b57cdc in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
  ...
  </code></pre>
  
  <p>As one can see instead of waiting for a response of the HTTP request, it picked up another event and started to process it. As a result I'm getting a huge number of frames (746) in the current thread before my application comes to a stop and then I see lines like this:</p>
  
  <pre><code>#0  0x00000033faa0efe0 in __pause_nocancel () from /lib64/libpthread.so.0
  #1  0x00000033faa0917b in __pthread_mutex_lock_full () from /lib64/libpthread.so.0
  #2  0x0000003404a702a3 in ?? () from /usr/lib64/libQtCore.so.4
  #3  0x0000003404a6cd95 in QMutex::lock() () from /usr/lib64/libQtCore.so.4
  #4  0x0000003404b57952 in QCoreApplication::postEvent(QObject*, QEvent*, int) () from /usr/lib64/libQtCore.so.4
  #5  0x000000000040e293 in DevicePlugin::destroyConnection (this=0x1267390, c=0x1a85fb0) at DevicePlugin.cpp:194
  #6  0x000000000040e5b6 in DevicePlugin::timerEvent (this=0x1267390, event=0x7fff902b9230) at DevicePlugin.cpp:254
  #7  0x0000003404b6698e in QObject::event(QEvent*) () from /usr/lib64/libQtCore.so.4
  #8  0x0000003404b57cdc in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/libQtCore.so.4
  ...
  </code></pre>
  
  <p>Could anyone kindly explain me what am I doing wrong here?</p>