Why do *Event functions declared in QWidget as protected ?
Why do *Event functions declared in QWidget as protected ? What's the reason ?
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
burkav84
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.
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
burkav84
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..
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
jpn
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 :confused:
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 ?
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
burkav84
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.
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
jpn
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 :confused:
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 ?
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
burkav84
But if it declared as private, it is possible to reimplement it in subclass :confused:
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.
Re: Why do *Event functions declared in QWidget as protected ?
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.. :p
Re: Why do *Event functions declared in QWidget as protected ?
Thank's Gopala Krishna and jpn for answers and links.
Re: Why do *Event functions declared in QWidget as protected ?
Quote:
Originally Posted by
jpn
Edit: Gopala Krishna, did you modify the post of yours? It looks different than by the time I started replying.. :p
No I posted 2 replies one after other. You should have started to reply after the 1st reply . Just a sheer coincidence !! ;)