title: How to sleep in a worker thread in Qt?
body: <p>I am creating an example to understand threads in Qt and want my worker thread to sleep for 1 second between each increment so I can see the debug output. But the sleep makes my main GUI thread non-responsive.</p>
  
  <p>Here is my slot functoin in <code>OddCounter</code> class.</p>
  
  <pre><code>void OddCounter::count()
  {
      for (int i = 0; i &lt; 10; i++)
      {
          counter += 2;
  
          qDebug() &lt;&lt; counter;
  
          QThread::sleep( 1 );
      }
  }
  </code></pre>
  
  <p>My mainwindow class which calls this thread is:</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
  
      oddCounter = new OddCounter;
  
      connect(this, SIGNAL(startOddCounter()), evenCounter, SLOT(count()), Qt::QueuedConnection );
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  
  void MainWindow::on_pushButton_clicked()
  {
      OddCounter oddCounter;
  
      oddCounter.moveToThread( &amp;thread );
  
      thread.start();
  
      emit startOddCounter();
  }
  </code></pre>
  
  <p>The problem is when I press the button, the counter works and displays the next increment after each second passed but the mainwindow is non responsive all this time! This is not right! I want my mainwindow to be responsive and only the thread should sleep. How do I do that?</p>