vendredi 2 novembre 2018

QTimer not called from worker class in different thread

I am working on Qt application, there I have created worker class to be handled in a different thread (which I have read is the recommended way to proceed instead of subclasing QThread) This is my relevant code so far:

void MonitoringWorker::process()
{
qDebug() << "Worker" ;
QTimer timer(this);
connect(&timer, SIGNAL(timeout()), this, SLOT(getCalculation()));
timer.start(1000);
}

And this is what I have in main:

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QThread* thread = new QThread;
Worker* worker = new Worker();
worker->moveToThread(thread);
QObject::connect(thread, SIGNAL(started()), worker, SLOT(process()));
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
return a.exec();
}

However the timer does not seem to be called. What am I doing wrong? Could someone explain? Note: process() method is public slot

Aucun commentaire:

Enregistrer un commentaire