Results 1 to 11 of 11

Thread: Why do *Event functions declared in QWidget as protected ?

  1. #1
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    3

    Default Why do *Event functions declared in QWidget as protected ?

    Why do *Event functions declared in QWidget as protected ? What's the reason ?

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by burkav84 View Post
    Why do *Event functions declared in QWidget as protected ? What's the reason ?
    *Event functions are mainly provided to override default response of a widget for an event and hence for a user its only useful when he overrides the class. This means only QWidget and classes derived from it are the accessors of *Event members and hence they are protected.
    That too making them public would mean a possible misuse of these functions by user - say for example when a user "calls" QWidget::mouseMoveEvent() instead of QCoreApplication::sendEvent() which is what the user would have probably wanted to do.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by burkav84 View Post
    Why do *Event functions declared in QWidget as protected ? What's the reason ?
    Because they are called "by the framework" (*). One is not not supposed to call them outside by hand (this is why they are not public). One can re-implement a virtual event handler in a subclass (this is why they are not private).

    (*) Notably QWidget::event() does the job of identifying different kind of events and delivering them into specialized event handlers if appropriate, like QWidget::mousePressEvent(), QWidget::keyPressEvent() and so on..
    J-P Nurmi

  4. #4
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    3

    Default Re: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by jpn View Post
    One can re-implement a virtual event handler in a subclass (this is why they are not private).
    But if it declared as private, it is possible to reimplement it in subclass
    Why not to implement them as private ? It may be caused that in reimplemented event handler it may be need to call QWidget::*Event() of the base class. Correct ?

  5. #5
    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: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by burkav84 View Post
    But if it declared as private, it is possible to reimplement it in subclass
    If they were private, they wouldn't be accessible in subclasses.

  6. #6
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    3

    Question Re: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by jpn View Post
    One can re-implement a virtual event handler in a subclass (this is why they are not private).
    But if it declared as private, it is possible to reimplement it in subclass
    Why not to implement them as private ? It may be caused that in reimplemented event handler it may be need to call QWidget::*Event() of the base class. Correct ?

  7. #7
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by burkav84 View Post
    But if it declared as private, it is possible to reimplement it in subclass
    Why not to implement them as private ? It may be caused that in reimplemented event handler it may be need to call QWidget::*Event() of the base class. Correct ?
    You can implement but you can't call base method in sub classes.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  8. #8
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Why do *Event functions declared in QWidget as protected ?

    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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

    Default Re: Why do *Event functions declared in QWidget as protected ?

    As already mentioned, you cannot access anything private (unless declared as a friend).

    What's the difference between public, private, and protected?

    Edit: Gopala Krishna, did you modify the post of yours? It looks different than by the time I started replying..
    J-P Nurmi

  10. #10
    Join Date
    Feb 2007
    Posts
    14
    Thanks
    3

    Default Re: Why do *Event functions declared in QWidget as protected ?

    Thank's Gopala Krishna and jpn for answers and links.

  11. #11
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Why do *Event functions declared in QWidget as protected ?

    Quote Originally Posted by jpn View Post
    Edit: Gopala Krishna, did you modify the post of yours? It looks different than by the time I started replying..
    No I posted 2 replies one after other. You should have started to reply after the 1st reply . Just a sheer coincidence !!
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. Qt/Embedded Installation error during make
    By mahe2310 in forum Installation and Deployment
    Replies: 5
    Last Post: 7th September 2006, 04:05
  3. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11
  4. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54
  5. Qt 4.1 and KDE 3.5.1 on OSX 10.2.8
    By Ptero-4 in forum Installation and Deployment
    Replies: 6
    Last Post: 6th February 2006, 02:44

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.