title: how to start QTimer so that the GUI does not hangs-RestartStoppedProcess()-code
body: <p>I have made new QTimer object in my class's ctor. When the application starts the timer also starts with the specified time. This timer keeps a track of all the process IDs and if finds that a particular process-id is not active(killed from task manager) then it restarts that particular process. Now the issue is my application lags a-bit due to this QTimer object and only after the timeout, the application becomes smooth. But after 5 seconds the timer starts again and the application starts lagging again. What is the best alternative to start a QTimer object apart from ctor of a class?</p>
  
  <pre><code>qTimer = new QTimer(0);
  
  connect(qTimer, SIGNAL(timeout()), this, SLOT(RestartStoppedProcess()), Qt::DirectConnection);
  connect(qTimer, SIGNAL(destroyed()), qTimer, SLOT(deleteLater()), Qt::DirectConnection);
  
  qTimer-&gt;setTimerType(Qt::VeryCoarseTimer);
  qTimer-&gt;start(5000);
  
  
  void ProcessMonitor::RestartStoppedProcess()
  {
      try
      {
          QProcess *objMonitorProcess = new QProcess(this);
          connect(objMonitorProcess, SIGNAL(finished(int,QProcess::ExitStatus)), objMonitorProcess, SLOT(deleteLater()));
          for(int i = 0; i &lt; ui-&gt;twShowProcess-&gt;rowCount(); i++)
          {
  #ifdef Q_WS_LIN
              //            objMonitorProcess-&gt;start("pidof", QStringList() &lt;&lt; (ui-&gt;twShowProcess-&gt;item(i, 0)-&gt;text()), QIODevice::ReadOnly);
              objMonitorProcess-&gt;start("pidof "+ (ui-&gt;twShowProcess-&gt;item(i, 0)-&gt;text()), QIODevice::ReadOnly);
  #elif Q_WS_WIN
              QString cmd("wmic process where ");
              QString qszFilters("\"processid=\'");
              QString qszSubFilters = qszFilters.append(ui-&gt;twShowProcess-&gt;item(i, 1)-&gt;text().append("\'").append("\"").append(" get name"));
              cmd.append(qszSubFilters);
              objMonitorProcess-&gt;start(cmd.toStdString().c_str(), QIODevice::ReadOnly);
  #else
              QString qszProcessName = ui-&gt;twShowProcess-&gt;item(i, 0)-&gt;text().split(".").takeFirst();
              objMonitorProcess-&gt;start("pgrep", QStringList() &lt;&lt; qszProcessName, QIODevice::ReadOnly);
  #endif
              if((objMonitorProcess-&gt;waitForStarted(4000) == true) &amp;&amp; (objMonitorProcess-&gt;state() == QProcess::Running))
              {
                  if(objMonitorProcess-&gt;waitForFinished(3000) == false)
                      continue;
                  else
                  {
                      QString qszProcessStatus = ui-&gt;twShowProcess-&gt;item(i, 3)-&gt;text();
                      if(qszProcessStatus.compare("Running") == 0)
                      {
                          QString qszStandardOutput, qszStandardError;
                          qszStandardOutput.clear(); qszStandardError.clear();
                          qszStandardOutput = QString(objMonitorProcess-&gt;readAllStandardOutput());
                          qszStandardError = QString(objMonitorProcess-&gt;readAllStandardError());
                          if(qszStandardError.simplified().compare("No Instance(s) Available.", Qt::CaseInsensitive) == 0 &amp;&amp; qszStandardOutput.simplified().isEmpty() == true)
                          {
                              ui-&gt;twShowProcess-&gt;selectRow(i);
                              if(ui-&gt;twShowProcess-&gt;selectedItems().at(0)-&gt;text().compare("LTtagdb.exe", Qt::CaseInsensitive) == 0 ||
                                      ui-&gt;twShowProcess-&gt;selectedItems().at(0)-&gt;text().compare("LTmessagebroker.exe", Qt::CaseInsensitive) == 0)
                                  this-&gt;StopAllApplicationsForcefully();
                              else
                                  this-&gt;on_actionStop_triggered();
  
                              if(this-&gt;ptrobjContextMenu-&gt;isVisible())
                                  this-&gt;ptrobjContextMenu-&gt;close();
  
                              ui-&gt;twShowProcess-&gt;clearSelection();
  
                              if(mobj_ProcessLogMap.mobj_ProcessAndLogMapping.contains(ui-&gt;twShowProcess-&gt;item(i, 8)-&gt;text()) == true)
                              {
                                  mobj_ProcessLogMap.mobj_ProcessAndLogMapping.remove(ui-&gt;twShowProcess-&gt;item(i, 8)-&gt;text());
                                  mobj_ProcessLogMap.mobj_ProcessAndLogMapping.insert(ui-&gt;twShowProcess-&gt;item(i, 8)-&gt;text(), QString(""));
                              }
                              else
                                  this-&gt;mobj_ProcessLogMap.mobj_ProcessAndLogMapping.insert(ui-&gt;twShowProcess-&gt;item(i, 8)-&gt;text(), QString(""));
                          }
  
                          if(ui-&gt;twShowProcess-&gt;item(i, 0)-&gt;text() == "LThistdb.exe")
                          {
                              if(IsServiceRunning(QString("LThistdb.exe")) == false)
                                  this-&gt;on_actionStopPostgreSQL_DB_Server_triggered();
                          }
                          qszStandardOutput.clear();
                      }
                  }
              }
              else
                  break;
  #ifdef Q_WS_WIN
              cmd.clear();
              qszFilters.clear();
              qszSubFilters.clear();
  #endif
          }
      }
      catch(QProcess::ProcessError pError)
      {
          QMessageBox objCrashExit;
          objCrashExit.information(this, "Crashed", "Process error returned code: " + QString::number(pError));
      }
      catch(...)
      {
          QMessageBox objCrashExit;
          objCrashExit.information(this, "Unknown Crash", "Unknown crash exit-child process may not be running correctly!");
      }
  }
  </code></pre>