title: Qt multithreading: How to update two QLabels?
body: <p>I am not a multithreading expert. 
  I know that the GUI should be managed by the main thread, however I'd need 2 things to be done by the mainthread simultanuously.
  The situation is the following:</p>
  
  <p>The user clicks on a pushbutton (to take a selfie), a count down timer starts (3 seconds). The user can see in a QLabel the numbers 3-2 changing every second. Meanwhile the user can see the camera data in another QLabel of the same window.</p>
  
  <p>In other words the mainthread should do 2 things:</p>
  
  <ul>
  <li>update QLabel1 to always show the timer</li>
  <li>update QLabel2 with the live videostram from the camera</li>
  </ul>
  
  <p>I am having some difficulties to achieve this. Could someone help me out?
  I am not necessarily asking for an easy trick/work around. I'd like to use <em>multithreading</em> that way I can improve my knowledge about this technique and not just use a one time easy/quick workaround...</p>
  
  <p>Thank you</p>
  
  <p>My current code:</p>
  
  <p>What I tried: when the user clicks the button called btnTakeSnap a new thread is started and in that thread the timer starts counting down and updating the labelTimeSnap (this is a QLabel in which I load "fancy" images with numbers 3-0). Once the timer reaches 0 a picture is taken.</p>
  
  <p>But I don't see my QLabel being updated with the timer. It is only when 0 is reached that suddenly the number 0 gets displayed in my QLabel.</p>
  
  <p>Any advice?</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      snapIndex=1;
  
      QString fileName = "../somePicture.jpg";
      QImage imageFrame;
  
      connect(ui-&gt;btnTakeSnap, SIGNAL(clicked()), this, SLOT(startTimerWorker()) );
  }
  
  
  void MainWindow::startTimerWorker()
  {
      timerSnapThread = new QThread(this);
      MainWindow *workerTimerSnap = new MainWindow();
  
      connect(timerSnapThread, &amp;QThread::started, workerTimerSnap, &amp;MainWindow::updateTimer);
      workerTimerSnap-&gt;moveToThread(timerSnapThread);
      timerSnapThread-&gt;start();
  
  }
  
  void MainWindow::updateTimer()
  {
      int selectedTimer;
  
      if(ui-&gt;rdBtntimer1s-&gt;isChecked())
      {selectedTimer = 1000;}
      if(ui-&gt;rdBtntimer3s-&gt;isChecked())
      {selectedTimer = 3000;}
  
      QString filename;
      QImage image;
  
      //timer
        if(selectedTimer == 3000) //3 seconds
        {
           QElapsedTimer t;
           t.start();
           while (t.elapsed() &lt; selectedTimer)
           {
               if(t.elapsed()==0)
               {
                  filename = "../../testImages/timer3.png";qDebug()&lt;&lt;"3";
                  image.load(filename);
                  image= image.scaled(ui-&gt;labelTimeSnap-&gt;width(), ui-&gt;labelTimeSnap-&gt;height(),Qt::KeepAspectRatio);
                  ui-&gt;labelTimeSnap-&gt;setPixmap(QPixmap::fromImage(image));
                }
  
               if(t.elapsed()==1000)
               {
                  filename = "../../testImages/timer2.png";qDebug()&lt;&lt;"2";
                  image.load(filename);
                  image= image.scaled(ui-&gt;labelTimeSnap-&gt;width(), ui-&gt;labelTimeSnap-&gt;height(),Qt::KeepAspectRatio);
                  ui-&gt;labelTimeSnap-&gt;setPixmap(QPixmap::fromImage(image));
               }
  
              if(t.elapsed()==2000)
              {
                  filename = "../../testImages/timer1.png";qDebug()&lt;&lt;"1";
                  image.load(filename);
                  image= image.scaled(ui-&gt;labelTimeSnap-&gt;width(), ui-&gt;labelTimeSnap-&gt;height(),Qt::KeepAspectRatio);
                  ui-&gt;labelTimeSnap-&gt;setPixmap(QPixmap::fromImage(image));
              }
  
           }
              takeSnap();
         }
  
         if(selectedTimer == 1000)
         {
             QElapsedTimer t;
             t.start();
             while (t.elapsed() &lt; selectedTimer)
             {
                  if(t.elapsed()==0)
                  {
                      filename = "../../testImages/timer1.png";
                      qDebug()&lt;&lt;"1";
                      image.load(filename);
                      image= image.scaled(ui-&gt;labelTimeSnap-&gt;width(), ui-&gt;labelTimeSnap-&gt;height(),Qt::KeepAspectRatio);
                      ui-&gt;labelTimeSnap-&gt;setPixmap(QPixmap::fromImage(image));
                  }
  
                  if(t.elapsed()==1000)
                  {
                      filename = "../../testImages/timer1.png";
                      qDebug()&lt;&lt;"0";
                      image.load(filename);
                      image= image.scaled(ui-&gt;labelTimeSnap-&gt;width(), ui-&gt;labelTimeSnap-&gt;height(),Qt::KeepAspectRatio);
                      ui-&gt;labelTimeSnap-&gt;setPixmap(QPixmap::fromImage(image));
                  }
              }
              takeSnap();
         }
  }
  
  
  void MainWindow::takeSnap()
  {
      static int i=0;
  
      cv::VideoCapture cap(CV_CAP_ANY);
      cv::Mat imgFrame;
      cap &gt;&gt; imgFrame;
  
      //BGR-&gt; RGB
      cv::cvtColor(imgFrame, imgFrame, CV_BGR2RGB);
  
      //Mat -&gt; QPixMap
      QImage img;
      img = QImage((uchar*)imgFrame.data, imgFrame.cols, imgFrame.rows, QImage::Format_RGB888);
      QPixmap pixmap = QPixmap::fromImage(img);
  
      int w = ui-&gt;labelSnap1-&gt;width();
      int h = ui-&gt;labelSnap1-&gt;height();
      if(i==0)
      {ui-&gt;labelSnap1-&gt;setPixmap(pixmap.scaled(w,h,Qt::KeepAspectRatio));}
      if(i==1)
      {ui-&gt;labelSnap2-&gt;setPixmap(pixmap.scaled(w,h,Qt::KeepAspectRatio));}
      if(i==2)
      {ui-&gt;labelSnap3-&gt;setPixmap(pixmap.scaled(w,h,Qt::KeepAspectRatio));}
  
      i++;
      if(i==3){i=0;}
  
      showNextSnap();
  
  }
  </code></pre>