title: Qt 5 : update QProgressBar during QThread work via signal
body: <p>I'm trying to update a QProgressDialog (owned by a QMainWindow class) along the execution of a QThread who process some time consuming operations. The thread emit some signals during operation in order to inform the calling app about progression. I'm looking to connect the progress signal emitted by the thread to the setValue slot of the QProgressDialog in order to update the progress bar.</p>
  
  <p>It doesn't work ! The progress dialog is not displayed. If I add a slot in my QMainWindow and connect it to the worker progress signal in order to display the value given by the thread throught qDebug output, I see that signals seems to be stacked during the threaded operation and unstacked only at the end of the thread.</p>
  
  <p>I have tryed the DirectConnection connect's option without any success.</p>
  
  <p>Here is my code :
  qapp.cpp</p>
  
  <pre><code>#include "qapp.h"
  #include &lt;threaded.h&gt;
  
  #include &lt;QVBoxLayout&gt;
  #include &lt;QPushButton&gt;
  #include &lt;QDebug&gt;
  #include &lt;QProgressDialog&gt;
  
  QApp::QApp(QWidget *parent) :
      QMainWindow(parent)
  {
      QVBoxLayout *mainLayout = new QVBoxLayout(this);
      QWidget *window = new QWidget(this);
      window-&gt;setLayout(mainLayout);
      setCentralWidget(window);
      QPushButton *button = new QPushButton("Run");
      mainLayout-&gt;addWidget(button);
      connect(button, SIGNAL(clicked(bool)), this, SLOT(doSomeWork()));
  }
  
  void QApp::doSomeWork()
  {
      qDebug() &lt;&lt; "do some work";
      Threaded worker;
      worker.doHeavyCaclulations();
  
      QProgressDialog progressDialog("Copying files...", "Abort Copy", 0, 10000, this);
      progressDialog.setWindowModality(Qt::WindowModal);
      progressDialog.setMinimumDuration(0);
      progressDialog.setValue(0);
  
      connect(&amp;worker, SIGNAL(progress(int)), &amp;progressDialog, SLOT(setValue(int)));
      connect(&amp;worker, SIGNAL(progress(int)), this, SLOT(displayProgress(int)));
  
      worker.wait();
      qDebug() &lt;&lt; "end of thread";
  }
  
  void QApp::displayProgress(int value)
  {
      qDebug() &lt;&lt; "data received" &lt;&lt; value;
  }
  
  QApp::~QApp()
  {
  
  }
  </code></pre>
  
  <p>threaded.cpp :</p>
  
  <pre><code>#include "threaded.h"
  #include &lt;QDebug&gt;
  
  Threaded::Threaded(QObject *parent) : QThread(parent)
  {
  
  }
  
  void Threaded::doHeavyCaclulations()
  {
      if (!isRunning())
      {
          qDebug() &lt;&lt; "start thread"  ;
          start();
      }
  
  }
  
  void Threaded::run()
  {
      qDebug() &lt;&lt; "running big loop";
      for(double k = 0 ; k &lt; 10000 ; k++)
      {
          qDebug() &lt;&lt; k;
          emit progress(k);
      }
  }
  </code></pre>
  
  <p>qapp.h</p>
  
  <pre><code>#ifndef QAPP_H
  #define QAPP_H
  
  #include &lt;QMainWindow&gt;
  
  class QApp : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit QApp(QWidget *parent = 0);
      ~QApp();
  
  private:
  
  private slots:
      void doSomeWork();
      void displayProgress(int value);
  };
  
  #endif // QAPP_H
  </code></pre>
  
  <p>threaded.h</p>
  
  <pre><code>#ifndef THREADED_H
  #define THREADED_H
  
  #include &lt;QObject&gt;
  #include &lt;QThread&gt;
  
  class Threaded : public QThread
  {
      Q_OBJECT
  public:
      explicit Threaded(QObject *parent = 0);
      void doHeavyCaclulations();
      void run();
  
  private:
  
  
  signals:
      void progress(int value);
  
  public slots:
  
  };
  
  #endif // THREADED_H
  </code></pre>
  
  <p>The output of this code with k &lt; 100 is :</p>
  
  <pre><code>do some work
  start thread
  running big loop
  0
  1
  2
  3
  [...]
  97
  98
  99
  end of big loop
  end of thread
  data received 17
  data received 18
  data received 19
  [...]
  data received 99
  </code></pre>
  
  <p>If I remplace 
  worker.wait();
  by</p>
  
  <pre><code> int k=0;
      while(worker.isRunning())
      {
          qDebug() &lt;&lt; "main " &lt;&lt; k;
          k++;
      }
  </code></pre>
  
  <p>I get outputs of the thread and output of the calling method interleaved. It confirm that my thread is independant of the calling method.</p>
  
  <p>Any idea about what I'm doing wrong ?</p>