title: How can I make my QThread block and wait for a function called from the main thread to return a value?
body: <p>I am doing some work in a QThread reimplementation. Every now and then, I'd like to ask the user a Yes/No question, so I was planning on using QMessageBox::question(). Problem is, I can't call it from the thread. That's not a big one, I can emit a signal that connects to a slot in the main GUI thread which will display the message box, but I also need the custom thread to block and wait for the message box to be dismissed and retrieve the return value as well (here, a QMessageBox::StandardButton). How do I get around to doing that?</p>
  
  <p><b>EDIT:</b>
  Will the following (pseudo-)code do the trick?</p>
  
  <pre><code>class MyThread
  {
  public:
      MyThread(QObject *parent)
      {
          connect(this, SIGNAL(inputRequired()), parent, SLOT(popMsgBox()), Qt::QueuedConnection);
      }
  
  void MyThread::run()
  {
      QMutex m;
      for (...)
      {
          if (something) 
          {
              m.lock();
              emit inputRequired();
              w.wait(&amp;m);
              m.unlock();
          }
  
          if (MyGui-&gt;ans_ == Yes) do_something();
      }
  }
  
  signals:
      void inputRequired();
  
  protected:
      QWaitCondition w;
  
  };
  
  void MyGui::popMsgBox()
  {
      ans_ = QMessageBox::question(this, "Question", "Yes or no?", Yes | No);
      MyThread-&gt;w-&gt;wakeAll();
  }
  </code></pre>