title: Work with QTimer, QThread and Progress Bar
body: <p>I would like to use calculation in separate from Ui thread. Calculating method — private slot of MainWindow Метод. During calculations, there is a gradual transfer of the calculated data in object OutputData — field of ProgressBar Window. The thread in which calculations are performed is also a field of the main window.</p>
  
  <p>Main Window constructor, where the thread is created and beginning of calculation is connected to the start of the thread:</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow) {
  ui-&gt;setupUi(this);
  
  calculation = new QThread(this);
  
  settings.setToDefault();
  outputData.setToDefault();
  calculationDone = false;
  
  connect(calculation, SIGNAL(started()), this, SLOT(calculate()));
  
  ui-&gt;results_display-&gt;setText("Загрузите &lt;b&gt;параметры&lt;/b&gt; и начинайте расчёты!");
  }
  </code></pre>
  
  <p>Push button method, starting the thread and modal window w/ ProgressBar:</p>
  
  <pre><code>void MainWindow::on_calculate_button_clicked() {
  ui-&gt;results_display-&gt;clear();
  ui-&gt;results_display2-&gt;clear();
  
  calculation-&gt;start();
  
  ///TODO QProgressDialog
  
  ProgressDialog progressDialog(&amp;outputData, this);
  progressDialog.setModal(true);
  progressDialog.exec();
  
  if (progressDialog.result() == QDialog::Rejected) {
      calculation-&gt;terminate();
      QMessageBox::critical(this, "Результат", "Расчёт был остановлен!");
  } else {
      if (progressDialog.result() == QDialog::Accepted) {
          calculation-&gt;quit();
          QMessageBox::about(this, "Результат", "Готово!");
          }
      }
  }
  </code></pre>
  
  <p>Modal window constructor sets parameters of ProgressBar, creates timer and set connection between timer and update method:</p>
  
  <pre><code>ProgressDialog::ProgressDialog(OutputData *outputData, QWidget *parent) :
  QDialog(parent),
  ui(new Ui::ProgressDialog) {
  ui-&gt;setupUi(this);
  
  data = outputData;
  
  ui-&gt;quantity_label-&gt;setText("0");
  ui-&gt;progressBar-&gt;setMinimum(0);
  ui-&gt;progressBar-&gt;setMaximum(static_cast&lt;int&gt;(data-&gt;outputSettings.aircraftQuantity));
  
  timer = new QTimer(this);
  timer-&gt;setSingleShot(false);
  connect(timer, SIGNAL(timeout()), this, SLOT(update()));
  timer-&gt;start(50);
  }
  </code></pre>
  
  <p>ProgressBar update method:</p>
  
  <pre><code>void ProgressDialog::update() {
  unsigned long aircraftsDone = data-&gt;results.size() + data-&gt;unprocessedAircrafts.size();
  ui-&gt;progressBar-&gt;setValue(static_cast&lt;int&gt;(aircraftsDone));
  ui-&gt;aircraftQunatityDone_label-&gt;setText(QString::number(aircraftsDone));
  ui-&gt;progressBar-&gt;repaint();
  
  if (aircraftsDone == data-&gt;outputSettings.aircraftQuantity) {
      accept();
     }
  }
  </code></pre>
  
  <p>Calculations currently work well, but no progress information is drawn or updated.</p>