I presume this is a newbie question, but hey, this is the newbie forum, right?
I have a console application with two threads: a worker thread and a communication thread (communicates over a tcp socket). The program works fine, but if I press ctrl-c, it exits quite raw. What I want is that the worker thread intercepts the ctrl-c and instructs the commthread to send a final message, and then gracefully stop instead of exiting roughly (in the current situation I do not really see how the program flow is going when exiting).
How do I ensure that the worker thread intercepts the ctrl-c and not the commthread? And how do I intercept the ctrl-C at all?
I tried this:
bool MyApp::event(QEvent *evt)
{
if (evt->type() == QEvent::KeyPress)}
{
// check for ctrl-c and if so, handle it and return true}
return QObject::event(evt);
However it appears that I do not receive any keypress events at all, no matter what I hit on the keyboard...
Note: I know about the signal aboutToQuit, but I want to make sure that QCoreApplication::exec() returns normally so that anything following that is executed.
Bookmarks