title: creating new thread using Qthread-Qt5
body: <p>I am trying to create a new thread <code>gpsthread</code> which should run in the back ground, and store the value.</p>
  
  <pre><code>class gpsthread: public QThread{
      Q_OBJECT
  private:nrega_status_t status2;
  
  public: 
  explicit gpsthread(QObject *parent = 0):QThread(parent) {
      // QTimer *t = new QTimer(this);
      // connect(t, SIGNAL(timeout()), this, SLOT(processgps()));
      // t-&gt;start(10000);
   }
   void run(){
      qDebug()&lt;&lt;"inside gps thread\n";
      QTimer *t = new QTimer(this);
       connect(t, SIGNAL(timeout()), this, SLOT(processgps()));
       t-&gt;start(10000);
      }
  
  public slots:void processgps(){
      int status2;
      status2=gps_management();
  }
  };
  </code></pre>
  
  <p>My main class is quickview.</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
  
  QString file = "qml/main.qml";
  QApplication app(argc, argv);
  TranslationTest myObj;
  QuickView view;
  subthread object;
  gpsthread obj;
  gprsthread gprs;
  view.rootContext()-&gt;setContextProperty("rootItem", (QObject *)&amp;myObj);
  
      obj.start();
  //from subthread
  QObject::connect(&amp;object, SIGNAL(batterytoqml(QVariant,QVariant)),item, SLOT(frombattery(QVariant,QVariant)));
  QObject::connect(&amp;gprs, SIGNAL(gprstoqml(QVariant)),item, SLOT(fromgprs(QVariant)));
  return app.exec();
  </code></pre>
  
  <p>}</p>
  
  <p>I have tried this as well </p>
  
  <pre><code>class gpsthread: public QThread{
      Q_OBJECT
  private:nrega_status_t status2;
  
  public:QTimer* t; 
  explicit gpsthread(QObject *parent = 0):QThread(parent) {
      // QTimer *t = new QTimer(this);
      // connect(t, SIGNAL(timeout()), this, SLOT(processgps()));
      // t-&gt;start(10000);
   }
   void run(){
      qDebug()&lt;&lt;"inside gps thread\n";
      t = new QTimer(this);
       connect(t, SIGNAL(timeout()), this, SLOT(processgps()));
       t-&gt;start(10000);
  exec();    
  }
  
  public slots:void processgps(){
      int status2;
      status2=gps_management();
  }
  };
  </code></pre>
  
  <p>But it is giving error saying</p>
  
  <pre><code> QObject: Cannot create children for a parent that is in a different thread
  </code></pre>
  
  <p>If I create object in constructor then also it will give the same error because the object will be created in the main thread.
  How to resolve this? </p>