title: Does QThread::sleep() require the event loop to be running?
body: <p>I have a simple client-server program written in Qt, where processes communicate using MPI. The basic design I'm trying to implement is the following:</p>
  
  <ol>
  <li><p>The first process (the "server") launches a GUI (derived from <code>QMainWindow</code>), which listens for messages from the clients (using repeat fire <code>QTimer</code>s and asynchronous MPI receive calls), updates the GUI depending on what messages it receives, and sends a reply to every message.</p></li>
  <li><p>Every other process (the "clients") runs in an infinite loop, and all they are intended to do is send a message to the server process, receive the reply, go to sleep for a while, then wake up and repeat. Every process instantiates a single object derived from <code>QThread</code>, and calls its <code>start()</code> method. The <code>run()</code> method of these classes all look like this:</p></li>
  </ol>
  
  <p>from foo.cpp:</p>
  
  <pre><code>void Foo::run()
  {
      while (true)
      {
          // Send message to the first process
          // Wait for a reply
          // Do uninteresting stuff with the reply
          sleep(3);    // also tried QThread::sleep(3)
      }
  }
  </code></pre>
  
  <p>In the client's code, there is no call to <code>exec()</code> anywhere, so no event loop should start.</p>
  
  <p>The problem is that the clients never wake up from sleeping (if I surround the <code>sleep()</code> call with two writes to a log file, only the first one is executed, control never reaches the second). Is this because I didn't start the event loop? And if so, what is the simplest way to achieve the desired functionality?</p>