title: Function not running with QtConcurrent::run() when using QFutureWatcher
body: <p>I want to call a function to delete files and folders from the system in a parallel thread called by <code>QtConcurrent::run()</code> (Qt for Embedded Linux 4.8). Using only a <code>QFuture&lt;bool&gt;</code> with <code>QFuture::waitForFinished()</code> to grab the result (I need to run some code right after the operation), I was able to make the system work.</p>
  
  <p>But I want to display the ongoing result of the operation in a <code>QProgressBar</code> derived class with its <code>setValue(int)</code> called via signals and slots mechanism from inside the delete function, and what I get with the above method is a freezed main thread while the operation isn't finished, and that is inadmissible. </p>
  
  <p>So I though about using <code>QFutureWatcher&lt;bool&gt;</code> and connecting it's <code>finished()</code> signal to another slot containing the remaining code to be run after the delete operation is finished.</p>
  
  <p>The problem I'm facing is that, when I do this, the delete function is simply not run by <code>QtConcurrent::run()</code>! I checked that with printed messages to Terminal. Everything that occurs is that the <code>QFutureWatcher</code> calls its <code>finished()</code> signal without any execution of the delete files function (and that also happens if I use <code>QFutureWatcher::waitForFinished()</code>).</p>
  
  <p>Is this some bug from Qt?</p>
  
  <p>Regarding code, it's pretty exactly as in Qt Assistant: create the QFuture and QFutureWatcher globally, connect the finished() signal with the slot, call <code>QtConcurrent::run()</code>, and <code>setFuture()</code> to the future. Nothing special.</p>
  
  <p>Any help appreciated.</p>
  
  <p>EDIT</p>
  
  <p>Following the request of Kuba, here is the relevant part of the code:</p>
  
  <pre><code>//Declared globally in the .cpp
  QFuture&lt;bool&gt; future;
  QFutureWatcher&lt;bool&gt; watcher;
  
  //
  void SelectRecordToDeleteWidget::slotDeleteRecordStateMachine()
  {
      switch (deleteRecordStateMachine)
      {
          case PrepareToDelete:
          {
              //...
              connect(&amp;watcher,SIGNAL(finished()),this,SLOT(slotDeleteRecordStateMachine()),Qt::UniqueConnection);
              //...
          }
              break;
  
          case DeleteRecords:
          {
              //...
              future = QtConcurrent::run(removeFiles, QString(DEFAULT_RECORD_DIR) + "/" + recordList.at(aaa).second.second, poProgressDialog, &amp;itemCounter);
  
              watcher.setFuture(future);
  
              qApp-&gt;processEvents();
              //...
          }
              break;
  
          case FinishDelete:
          {
              //Run code after deleting files
          }
              break;
  
          default:
              break;
      }
  }
  </code></pre>
  
  <p>This is all the code using QFuture and QFutureWatcher. The <code>removeFiles</code> is as follows (not forgetting that it works well without QFutureWatcher):</p>
  
  <pre><code>bool removeFiles(const QString dirName, Interface::ProgressDialog* const poProgressDialog, qint32* const itemDeletedCounter)
  {
      bool result = true;
  
      try
      {
          QDir dir(dirName);
  
          if (dir.exists())
          {
              Q_FOREACH (QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst))
              {
      //            if (Q_UNLIKELY(poProgressDialog-&gt;wasCanceled()))
      //                break;
  
                  if (info.isDir())
                  {
                      result = removeFiles(info.absoluteFilePath(),poProgressDialog,itemDeletedCounter);
  
                      if (!result)
                          return result;
                  }
                  else
                  {
                      result = QFile::remove(info.absoluteFilePath());
  
                      if (!result)
                          return result;
  
                      if (!QMetaObject::invokeMethod(poProgressDialog, "setValue",
                                                Qt::BlockingQueuedConnection,
                                                Q_ARG(qint32, *itemDeletedCounter)))
                      {
                          mDebugS(QString("removeFiles: %1QMetaObject::invokeMethod(poProgressDialog, \"setValue\"... failed!"));
                      }
  
                      ++(*itemDeletedCounter);
  
  //                    mDebugS(QString("removeFiles: %1").arg(*itemDeletedCounter));
                  }
              }
  
              result = dir.rmdir(dirName);
          }
      }
      catch (...)
      {
          const QString strTemp = QString("An error in a call to removeFiles");
  
          mDebugS(strTemp);
          mLog(strTemp);
      }
  
      return result;
  }
  </code></pre>