Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Last active June 7, 2016 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/8c06389db09cac53dfbff099ab9b499f to your computer and use it in GitHub Desktop.
Save sivabudh/8c06389db09cac53dfbff099ab9b499f to your computer and use it in GitHub Desktop.
How to handle thread termination
QTimer* timer = new Qtimer();
connect(timer, SIGNAL(timeout(1)), thread, SLOT(threaCode));
// will get called every 1 milliseconds
void threadCode()
{
timer->stop();
tryReceiveBytes(5, bytes);
if(dead)
return;
if not receive anything
timer->start()
return;
// received message AND not dead
// --> should do processing
finally {
timer->start()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment