Results 1 to 2 of 2

Thread: shortcut from main

  1. #1
    Join Date
    Jan 2007
    Posts
    26
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    10

    Default shortcut from main

    Is it possible to create a shortcut or connection from main() that quits the app using a keypress? i.e. not from within a widget

    I realize qApp->quit() is the call I need, but Im not sure how to connect that to a keypress shortcut that doesnt come from a button click or other type of SIGNAL.

    .. and when I do something like this:

    (void) new QShortcut(Qt::Key_Escape, &app, (QApplication::quit()));

    i get invalid use of void expression

    Thank you,
    ChasW

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: shortcut from main

    QShortcut constructor takes a QWidget* and you are also missing the SLOT() macro:
    Qt Code:
    1. new QShortcut(Qt::Key_Escape, anyWidget, SLOT(close()));
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 2nd February 2007 at 23:46. Reason: I must have been very drunk while writing this.. correcting!
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    ChasW (2nd February 2007)

Similar Threads

  1. Main Thread (GUI Thread)
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 17:07
  2. How to close all windows that were created in main()?
    By Mister_Crac in forum Qt Programming
    Replies: 6
    Last Post: 13th November 2006, 11:57
  3. Replies: 5
    Last Post: 5th August 2006, 00:44
  4. Replies: 3
    Last Post: 31st March 2006, 19:38
  5. While statement inside the main loop
    By OnionRingOfDoom in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2006, 19:17

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.