title: Cannot send events to objects owned by a different thread while runing a member method on another QThread
body: <p>I need to run a method in my MainWindow class, in a different thread as it is a length and time consuming process.</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      initGui(ui);
  
      // Create background worker thread
      backgroundWorker = QThread::create([this] {
          backgroundMethod();
      });
  
      // Define when finished with work
      connect(backgroundWorker, &amp;QThread::finished, [this] () {
          qDebug() &lt;&lt; "Background method has finished";
  
          // Stop movie
          ui-&gt;lblLoading-&gt;movie()-&gt;stop();
  
          // go to next screen
          ui-&gt;tabbarMainWidget-&gt;tabBar()-&gt;setCurrentIndex(1);
  
          //show backup icon files
          if(filesToBackup.size() &gt; 0) {
              qDebug() &lt;&lt; "There are files to backup!";
              ui-&gt;lblInfoImage-&gt;show();
          }
      });
  
      // Start worker thread
      backgroundWorker-&gt;start();
  }
  </code></pre>
  
  <p><strong>backgroundMethod</strong></p>
  
  <pre><code>void MainWindow::backgroundMethod() {
      for (int i = 0; i &lt; 10; i++) {
          qDebug() &lt;&lt; "Hello World";
      }
  }
  </code></pre>
  
  <p>I am omitting alot of code as it is not necessary. The basic logic is as follows:</p>
  
  <ol>
  <li><p>Start new thread using <a href="https://doc.qt.io/qt-5/qthread.html#create-1" rel="nofollow noreferrer">QThread::create()</a></p></li>
  <li><p>Run the <code>backgroundMethod()</code> until completed while having the UI free for other work.</p></li>
  <li><p>When the <code>backgroundMethod()</code> has finished, the <code>QThread</code> should emit the <a href="https://doc.qt.io/qt-5/qthread.html#finished" rel="nofollow noreferrer">finished()</a> signal.</p></li>
  <li><p>I have a connection setup between the <code>backgroundWorker</code> thread's <code>finished()</code> and the lambda to run some more code.</p></li>
  </ol>
  
  <p><strong>The problem:</strong></p>
  
  <blockquote>
    <p>Background method has finished </p>
    
    <p>QObject::killTimer: Timers cannot be stopped from another thread </p>
    
    <p>ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 0x0x2801d950. Receiver 'lblInfoImage'
    (of type 'QLabel') was created in thread 0x0x2688c4b0", file
    kernel\qcoreapplication.cpp, line 578 04:11:28: The program has
    unexpectedly finished.</p>
  </blockquote>
  
  <p>In short, I am accessing the <code>lblInfoImage</code> on the <code>backgroundWorker</code> thread. I understood that using the <a href="https://doc.qt.io/qt-5/signalsandslots.html" rel="nofollow noreferrer">signal/slot mechanism</a> should cater for this issue, where my use of it is correct.</p>
  
  <p>I am not sure why this is happening, <strong>I need some help in understanding what I did to cause the problem and how I can fix it</strong></p>