When the timer expires, the timeout
event is queued to the event queue of your worker QThread. However, your worker QThread is busy executing doWork()
, so the event can't be processed. Once the thread completes the doWork
, control returns the the QThread's event loop and the timeout
event is executed.
The simplest approach to fixing this would be to manually invoke the event loop using QCoreApplication::processEvents()
at certain intervals throughout the execution of doWork()
. This will allow the QThread to execute the timeout
event earlier.
Alternative, you can use a different thread to perform these estimations. If they are not too performance-intensive, you can even use the GUI/main thread. The GUI/main thread is expected to remain "responsive" to events (otherwise the application appears to hang) so it can process the timeout
event in a timely manner.