Instantly share code, notes, and snippets.

Embed
What would you like to do?
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