I am trying to start a QTimer in a specific thread. However, the timer does not seem to execute and nothing is printing out. Is it something to do with the timer, the slot o
As I commented (further information in the link) you are doing it wrong :
doIt()
). They should be separated.QThread
in your case. Worse, you are overriding the run
method without any consideration of what it was doing.This portion of code should be enough
QThread* somethread = new QThread(this);
QTimer* timer = new QTimer(0); //parent must be null
timer->setInterval(1);
timer->moveToThread(somethread);
//connect what you want
somethread->start();
Now (Qt version >= 4.7) by default QThread
starts a event loop in his run()
method. In order to run inside a thread, you just need to move the object. Read the doc...