Qt-interest Archive, January 2007
qthread and qtimer?
Message 1 in thread
Hi,
I wants to use a thread with an event loop and a qtimer.
I have tryed to do like this
void MyThread::run()
{
QTimer *timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(timedone()));
timer->start(0);
exec();
}
but it seems that it don't works : I have the following warning :
QObject: Cannot create children for a parent that is in a different thread.
the timer works, the timedone() function is call but in the main thread,
not in MyThread.
I use QT4.2.2. visual c++2005 windows XP.. Is it a bug ? or I haven't
understand how to do that correctly ?
Best regards,
Yannick
--
[ signature omitted ]
Message 2 in thread
On Wednesday 24 January 2007 18:57, yannick kohn wrote:
> Hi,
>
> I wants to use a thread with an event loop and a qtimer.
> I have tryed to do like this
>
>
> void MyThread::run()
> {
> QTimer *timer=new QTimer(this);
> connect(timer,SIGNAL(timeout()),this,SLOT(timedone()));
> timer->start(0);
> exec();
> }
>
> but it seems that it don't works : I have the following warning :
> QObject: Cannot create children for a parent that is in a different thread.
You are creating your QTimer with a parent that was created in the different
thread.
"The child of a QObject must always be created in the thread where the parent
was created. This implies, among other things, that you should never pass the
QThread object (this) as the parent of an object created in the thread (since
the QThread object itself was created in another thread)."
Regards,
Enar
--
[ signature omitted ]