QTime or QTimer wait for timeout
Posted
by
user968243
on Stack Overflow
See other posts from Stack Overflow
or by user968243
Published on 2012-04-01T04:17:15Z
Indexed on
2012/06/05
16:40 UTC
Read the original article
Hit count: 152
I'm writting a Qt application, and I have a four hour loop (in a seperate thread). In that four hour loop, I have to:
- do stuff with the serial port;
- wait a fixed period of time;
- do some more stuff with the serial port;
- wait an arbitrary amount of time.
- when 500ms have past, do more stuff;
- Go to 1. and repeat for four hours.
Currently, my method of doing this is really bad, and crashes some computers. I have a whole bunch of code, but the following snippet basically shows the problem. The CPU goes to ~100% and eventually can crash the computer.
void CRelayduinoUserControl::wait(int timeMS)
{
int curTime = loopTimer->elapsed();
while(loopTimer->elapsed() < curTime + timeMS);
}
I need to somehow wait for a particular amount of time to pass before continuing on with the program. Is there some function which will just wait for some arbitrary period of time while keeping all the timers going?
© Stack Overflow or respective owner