Results 1 to 3 of 3

Thread: General question about events overriding

  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default General question about events overriding

    Hello,
    what are the best practices when overriding events? Should I always call the base class implementation or not? Sometimes in the docs I read "the default implementation does nothing", but most of the time there is no indication. Of course the safest way is to always call the base class, but that's error-prone.

    Also, I believe some base class implementions are meant to be called before my own code, while others should be called after (such as key press events). How do you know that? Nothing better than guessing?

    Thank you

  2. #2
    Join Date
    Aug 2009
    Posts
    6
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General question about events overriding

    Quote Originally Posted by mattc View Post
    Should I always call the base class implementation or not?
    I think you shouldn't... It depends on particular situation.

    For example, if you want to get zoom by Ctrl+wheel you should reimplement wheelEvent and if the Ctrl modifier is active you zoom you widget, and in the other case (if Ctrl is inactive) you'll call base class implementation and it'll scroll the area. But in first case there is no need to call base impl - you want your widget just to zoom in/out but not to scroll.

    And if you want to get smth done by pressing Enter in the widget derived from QLineEdit you should implement "Enter" case but in the other cases you should! call base impl otherwise you widget wouldn't act like a QLineEdit.

    And sometimes you need, for example, just to emit some signals or update some data on the event. Then you reimplement event, make you part and the always call base impl.

    Hope I helped a bit =)

  3. #3
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: General question about events overriding

    I asked the question because I was unsure about the QShowEvent. Should I call the base implementation or not? Before or after my own code?

    Then I started wondering about other events until I realized that I was not sure about anyone of them!

    I mean: I am supposed to browse the Qt sources in order to choose whether to call a base implementation or not? Not that I am afraid of that, just curious about what's the best practice.
    Last edited by mattc; 14th September 2009 at 16:17.

Similar Threads

  1. Replies: 14
    Last Post: 8th September 2009, 11:01
  2. General Question about Qt4 Model/View
    By reed in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2008, 15:06
  3. how to corss compile for windows in Linux
    By safknw in forum Qt Programming
    Replies: 24
    Last Post: 13th May 2006, 05:23

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