tzhu
18th March 2009, 10:51
Hi, I just started learning Qt several days ago, and I got stuck on this for a while now. I'm trying to create a new thread in which a QTimer would run, and connect the timer's timeout() signal to a function running in that thread. Here is one of the things that I tried:
I try to run a timer here connected to a slot in MyObject (onTimeOut)
class MyThread : public QThread
{
public:
MyThread();
~MyThread();
QTimer *timer;
void run();
};
void MyThread::run()
{
MyObject object;
timer = new QTimer;
connect(timer, SIGNAL(timeout()), &object, SLOT(onTimeOut()));
timer->start(500);
exec();
}
To my understanding this should call onTimeOut every half second, but that's not happening. Is there something that I'm missing completely?
I try to run a timer here connected to a slot in MyObject (onTimeOut)
class MyThread : public QThread
{
public:
MyThread();
~MyThread();
QTimer *timer;
void run();
};
void MyThread::run()
{
MyObject object;
timer = new QTimer;
connect(timer, SIGNAL(timeout()), &object, SLOT(onTimeOut()));
timer->start(500);
exec();
}
To my understanding this should call onTimeOut every half second, but that's not happening. Is there something that I'm missing completely?