Results 1 to 4 of 4

Thread: Event Handler

  1. #1
    Join Date
    Dec 2013
    Posts
    14
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default Event Handler

    I have a need (real) to process raw events from the QApplication. What I have been unable to discern as yet is how to convert a raw QEvent into QFocusEvent, QKeyEvent, and such. Is there a place in the Qt sources where I can look for the conversions and get a good definition of the contents (other than type) of a QEvent? Specifically, how is an event mapped to a specific QObject and where is the extra information such as which key was pressed or mouse button pressed?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,490
    Thanks
    252
    Thanked 717 Times in 707 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Event Handler

    You use QEvent::type() to find out what it is, and qobject_cast< whatever * >( event ) to cast it to a QEvent-based instance of that type. QEvent types derived from QInputEvent will contain the QObject pointer of the instance that generated them, and other event classes derived from QEvent may have them as well.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Event Handler

    I don't think qobject_cast will work on QEvent as it is not a QObject derived class.

    But checking type plus static_cast or dynamic_cast should work fine.

    One way to see all events and the objects they are sent to is to install an event filter on the QApplication instance.
    The eventFilter() method gets both the event and the receiver object.

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:

    d_stranz (29th October 2014)

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,490
    Thanks
    252
    Thanked 717 Times in 707 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Event Handler

    I don't think qobject_cast will work on QEvent as it is not a QObject derived class.
    Duh, yes, my mistake.

Similar Threads

  1. Key Event handler
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 5th December 2009, 10:32
  2. How to write correctly an event handler
    By franco.amato in forum Qt Programming
    Replies: 10
    Last Post: 3rd December 2009, 07:52
  3. Emitting signals from event handler
    By MarkoSan in forum Qt Programming
    Replies: 1
    Last Post: 3rd December 2009, 07:26
  4. Deleting objects in their event handler
    By drhex in forum Qt Programming
    Replies: 7
    Last Post: 6th May 2009, 16:08
  5. event handler
    By mattia in forum Newbie
    Replies: 10
    Last Post: 8th November 2007, 12:54

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.