Hello everybody,
I'm using threads ... and I've got a question. I've subclassed QThread and when I call start() the function below is called. Great. Now I thought there's be two ways of doing things: the first way with a forever loop - it works fine; and the second way, with a timer. My question: How do I connect the timer properly?

update() is a func in 'this' i.e. MyClass where I do the work.

Qt Code:
  1. void MyClass::run()
  2. {
  3. //can do this ....
  4.  
  5. forever{
  6. update();
  7. sleep(3);//seconds
  8. }
  9. return;
  10.  
  11. //or could do this...
  12.  
  13. QTimer* timer = new QTimer();
  14. timer->setInterval(3000);
  15. connect(timer, SIGNAL(timeout()), this, SLOT(update()), Qt::QueuedConnection);
  16.  
  17. exec();
  18.  
  19. delete timer;
  20.  
  21. return;
  22. }
To copy to clipboard, switch view to plain text mode