It depends on whether you just want the task to happen periodically or or an event.
If you want to do it periodically in the background then I'd suggest a timer.
http://stackoverflow.com/questions/3236 ... ng-a-timer
The timer will periodically call a function that contains the code that you wish to run.
Your code should not contain an infinite loop, you are relying on the QT timer to call your function again and again periodically.