title: Pause / resume Qthread from Worker
body: <p>In the Worker Class I have two functions who works and control the thread, start() and abort()   </p>
  
  <pre><code>void Worker::requestWork()
  {
      mutex.lock();
      _working = true;
      _abort = false;
      qDebug()&lt;&lt;"Le thread travail de"&lt;&lt;this-&gt;myId&lt;&lt;" "&lt;&lt;thread()-&gt;currentThreadId();
      mutex.unlock();
     emit workRequested();
  }
  
  void Worker::abort()
  {
      mutex.lock();
      if(_working) {
         _abort = true;
         qDebug()&lt;&lt;"Le thread "&lt;&lt;thread()-&gt;currentThreadId()&lt;&lt;" s'arrete";
      }
      mutex.unlock();
  }
  </code></pre>
  
  <p>As you can see the workrequest emit a signal saying to the thread to start to work. And because the Worker Class is in the thread, how can I pause or restore it? From the worker class? from the MainWindow?</p>
  
  <p>and now the Whole code.Mainwindow Class.    </p>
  
  <pre><code>    MainWindow::MainWindow(QWidget *parent) :    
      QMainWindow(parent),    
      ui(new Ui::MainWindow)    
      {    
          ui-&gt;setupUi(this);
          QObject::connect(ui-&gt;lineEdit,SIGNAL(textChanged(QString)),this,SLOT(command(QString)));
          thread = new QThread();
          worker = new Worker();
          worker-&gt;moveToThread(thread);
          connect(worker, SIGNAL(valueChanged(QString)), ui-&gt;label,  SLOT(setText(QString)));
          connect(worker, SIGNAL(workRequested()), thread, SLOT(start()));
          connect(thread, SIGNAL(started()), worker, SLOT(doWork()));
          connect(worker, SIGNAL(finished()), thread, SLOT(quit()), Qt::DirectConnection);
       }
  
  //QLineEdit send signal to slot "command" permit to control the thread
  void MainWindow::command(QString text){
  qDebug()&lt;&lt;"le message a bien ete intercepte";
  qDebug()&lt;&lt;ui-&gt;lineEdit-&gt;text();
  if (text.contains("help"))
      qDebug()&lt;&lt;"heeeelp";
  if (text.contains("pause")){
       worker-&gt;Paused();
       if(thread-&gt;isRunning()){}
           //cond.wait()
  }
  
  if (text.contains("restart")){
      worker-&gt;Restarted();
      if (!thread-&gt;isRunning()){}
          //cond.wakeAll();
  }
  
  if (text.contains("stopped")){
      worker-&gt;Paused();
      thread-&gt;wait();
  }
  if (text.contains("start")){
      worker-&gt;requestWork();
  
  }
  
  if (text.contains("destroyed")){
      worker-&gt;destroyed();
  }
  
  }
  </code></pre>
  
  <p>So my question is: how to pause and restart the thread from the command() slot when the User insert "Pause" ?</p>