Hi every body, I'm trying to make a window and show a time in every 1 minutes. This is what what I wrote to do that:

MyThread .h file:
Qt Code:
  1. class MyThread : public QThread
  2. {
  3. Q_OBJECT
  4. private:
  5. MainWindow *w;
  6. QTimer *timer;
  7. public:
  8. MyThread( QObject* parent );
  9. void run();
  10. public slots:
  11. void ToDo();
  12. };
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. MainWindow mw;
  2. MyThread::MyThread( QObject* parent ) : QThread( parent )
  3. {
  4. // nothing to do !!!
  5. }
  6.  
  7. void MyThread::run()
  8. {
  9. mw.show();
  10. timer = new QTimer(this);
  11. connect(timer,SIGNAL(timeout()), this, SLOT(ToDo()));
  12. timer->setInterval(2009);
  13. timer->start();
  14. return a.exec();
  15. }
  16. void MyThread::ToDo() {
  17. long i=0,h=0,m=0,s=0;
  18. while(i<3)
  19. {
  20. std::string str = "Time: ";
  21. char msg[100];
  22. Converter(gTime,h,m,s);
  23. sprintf(msg,"%02ld:%02ld:%02ld",h,m,s);
  24. str += msg;
  25. w->setText(QString::fromUtf8(str.c_str(),str.size()));
  26. sleep(1);
  27. i++;
  28. gTime--;
  29. }
  30. a.closeAllWindows();
  31. }
  32.  
  33. int main()
  34. {
  35. MyThread mt(0);
  36. mt.start();
  37. mt.wait();
  38. }
To copy to clipboard, switch view to plain text mode 

It is compiled but this is the error when I try to execute the program:

QObject: Cannot create children for a parent that is in a different thread.
(Parent is MyThread(0xbfbc4cac), parent's thread is QThread(0x80843a0), current thread is MyThread(0xbfbc4cac)
Thanks for your consideration