title: How to run a timer inside a QThread?
body: <p>I would like to run a timer inside a QThread. I have written some code in which i am getting some error during the run time. Please guide me into the right direction. What am I doing wrong?</p>
  
  <pre><code>(Parent is QThread(0x1498d10), parent's thread is QThread(0x11272b0), current thread is QThread(0x1498d10)
  </code></pre>
  
  <p>mainwindow.h //main .h file</p>
  
  <pre><code>#ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  #include "mythread.h"
  namespace Ui {
  class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
      Q_OBJECT
  
  public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
      MyThread *myt;
  
  private:
      Ui::MainWindow *ui;
  };
  
  #endif // MAINWINDOW_H
  </code></pre>
  
  <p>mainwindow.cpp //main .cpp file</p>
  
  <pre><code>#include "mainwindow.h"
  #include "ui_mainwindow.h"
  
  MainWindow::MainWindow(QWidget *parent) :
      QMainWindow(parent),
      ui(new Ui::MainWindow)
  {
      ui-&gt;setupUi(this);
      myt=new MyThread();
      myt-&gt;start();
      MainWindow w;
  }
  
  MainWindow::~MainWindow()
  {
      delete ui;
  }
  </code></pre>
  
  <p>mythread.h   // class for thread</p>
  
  <pre><code>#ifndef MYTHREAD_H
  #define MYTHREAD_H
  #include &lt;QThread&gt;
  #include &lt;QTimer&gt;
  class MyThread:public QThread
  {
  public:
      MyThread();
      void run();
     QTimer *thr;
  public slots:
     void slo();
  };
  
  #endif // MYTHREAD_H
  </code></pre>
  
  <p>mythread.cpp</p>
  
  <pre><code>#include "mythread.h"
  
  MyThread::MyThread()
  {
      thr= new QTimer();
      connect(thr,SIGNAL(timeout()),this,SLOT(slo()));
  }
   void MyThread::run()
   {
      thr-&gt;start(1000);
   }
  void MyThread::slo()
  {
      int i,j=0;
      i=i+j;
  }
  </code></pre>