Results 1 to 6 of 6

Thread: Event Rationale

  1. #1
    Join Date
    Jun 2007
    Posts
    4
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Event Rationale

    Hi
    I'm still plugging away at the book http://www.beginning-kdevelop-programming.co.uk/

    At the moment I'm looking at events ( Keyboard presently )
    I want to know if anyone can explain the rationale for having events as virtual protected functions and not as slots which would be considerably easier for people to access them than the current situation where the only way to access them is to subclass the base class.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Event Rationale

    How would they access them and what for?

    You have to pass some event as a parameter to every event handler and most of the events come from Qt's heart. Users rarely need to create them. If you want to do something with an event handler, it's because you want to change the behaviour of a widget and this calls for a new class. If you just want to use it, normal methods, slots and signals should be enough. They are more convenient too.


    Edit: I've just skimmed through your book. You have a memory leak in ChapterFiveDataTableWidget::polish() on page 150. Better create that password dialog on the stack.
    Last edited by jacek; 20th July 2007 at 14:52.

  3. #3
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Event Rationale

    I think you misread pseudonyms post. He/she is asking why events are as they exist in Qt now, when signals could have been used instead.

    I'm not exactly sure why (though I would hazard a guess at performance loss).

    However, subclassing is not the only way to catch an event. You can also use event filters.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

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

    pseudonym67 (20th July 2007)

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Event Rationale

    Quote Originally Posted by Michiel View Post
    I think you misread pseudonyms post. He/she is asking why events are as they exist in Qt now, when signals could have been used instead.
    Maybe, but in such case the explanation is simple. Without events Qt wouldn't be an even-driven programming framework --- signals and slots are synchronous (except for queued connections, but these use events underneath).

  6. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Event Rationale

    Events do not have any meaning to them. The user has done something: press a key on the keyboard, moved a mouse, etc. Signals do have semantic meaning, however. Objects take these meaningless events and make signals out of them. For example, a QPushButton has been pressed.

    Would you really want a mouseMoved() signal every time the mouse moved a pixel along the screen? Of course not! Qt keeps all of that low level chatter down in the event system. You typically only have to worry about them when you're writing new QWidgets.

  7. #6
    Join Date
    Jun 2007
    Posts
    4
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Event Rationale

    The case in point is a demonstration project to handle key presses the point is that as signals if you wanted to interpret key presses or mouse move events then you could do it without subclassing.
    If I understand it correctly this is exactly what event filters allow you to do.

Similar Threads

  1. QDockWidget-title
    By moowy in forum Qt Programming
    Replies: 18
    Last Post: 23rd April 2014, 20:13
  2. Create new an event, help me?
    By dungsivn in forum Qt Programming
    Replies: 6
    Last Post: 4th July 2007, 11:22
  3. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05
  4. pixmap onmousemove event help
    By bluesguy82 in forum Qt Programming
    Replies: 11
    Last Post: 9th August 2006, 14:15
  5. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.