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)
{
public:
MyThread();
~MyThread();
void run();
};
void MyThread::run()
{
MyObject object;
connect(timer, SIGNAL(timeout()), &object, SLOT(onTimeOut()));
timer->start(500);
exec();
}
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 copy to clipboard, switch view to plain text mode
To my understanding this should call onTimeOut every half second, but that's not happening. Is there something that I'm missing completely?
Bookmarks