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:
Code:
{ Q_OBJECT private: MainWindow *w; QTimer *timer; public: void run(); public slots: void ToDo(); };
main.cpp
Code:
MainWindow mw; { // nothing to do !!! } void MyThread::run() { mw.show(); connect(timer,SIGNAL(timeout()), this, SLOT(ToDo())); timer->setInterval(2009); timer->start(); return a.exec(); } void MyThread::ToDo() { long i=0,h=0,m=0,s=0; while(i<3) { std::string str = "Time: "; char msg[100]; Converter(gTime,h,m,s); sprintf(msg,"%02ld:%02ld:%02ld",h,m,s); str += msg; sleep(1); i++; gTime--; } a.closeAllWindows(); } int main() { MyThread mt(0); mt.start(); mt.wait(); }
It is compiled but this is the error when I try to execute the program:
Thanks for your considerationQuote:
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)