title: Qt5: How to wait for a signal in a thread?
body: <p>Probably the title question is not very explicit. I am using Qt5 on Windows7.</p>
  
  <p>In a thread (QThread) at some point, in the <code>"process()"</code> function/method, I must wait for the <code>"encrypted()"</code> SIGNAL belonging to a QSslSocket I am using in this thread. Also I suppose I should use a QTimer and wait for a <code>"timeout()"</code> SIGNAL in order to avoid getting blocked in an infinite loop...<br>
  What I have now is:    </p>
  
  <pre><code>// start processing data
  void Worker::process()
  {
      status = 0;
      connect(sslSocket, SIGNAL(encrypted()), this, SLOT(encryptionStarted()));
      QTimer timer;
      connect(&amp;timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
      timer.start(10000);
      while(status == 0)
      {
          QThread::msleep(5);
      }
  
      qDebug("Ok, exited loop!");
  
      // other_things here
      // .................
      // end other_things
  
      emit finished();
  }
  
  // slot (for timer)
  void Worker::timerTimeout()
  {
      status = 1;
  }
  
  // slot (for SSL socket encryption ready)
  void Worker::encryptionStarted()
  {
      status = 2;
  }
  </code></pre>
  
  <p>Well, obviously it doesn't work. It stays in that while-loop forever...<br>
  So, the question is: Is there a way to solve this problem? How can I wait for that <code>"encrypted()"</code> SIGNAL but not more than - let's say 10 seconds - in order to avoid getting stuck in that waiting-loop/thread?    </p>