Results 1 to 9 of 9

Thread: Ctrl-C interception

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Ctrl-C interception

    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.
    Last edited by T_h_e_o; 25th April 2012 at 16:03.

Similar Threads

  1. CTRL-+ in keyPressEvent
    By The_Fallen in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2011, 22:40
  2. Interception of GET requests to the server
    By artkor in forum Newbie
    Replies: 4
    Last Post: 29th September 2010, 08:59
  3. filterout the Alt+Ctrl+Del
    By sudhansu in forum Qt Programming
    Replies: 6
    Last Post: 25th March 2010, 07:55
  4. disable ALT+CTRL+DEL!!!!
    By phillip_Qt in forum Qt Programming
    Replies: 10
    Last Post: 3rd November 2009, 09:23
  5. CTrl + A
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2008, 09:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.