Handlery eventów w Qt to zwykłe metody wirtualne. Nie jest tak jak mówisz, że każde przeładowanie jest niejawnie wołane.
Qt 4.7 Reference: The Event System napisał(a)
The normal way for an event to be delivered is by calling a virtual function. For example, QPaintEvent is delivered by calling QWidget::paintEvent(). This virtual function is responsible for reacting appropriately, normally by repainting the widget. If you do not perform all the necessary work in your implementation of the virtual function, you may need to call the base class's implementation.
Może po prostu chcesz, aby klasa najbardziej bazowa zareagowała na event jako pierwsza, a później ewentualnie ta najbardziej pochodna, która przeładowała dany event? Coś takiego:
class Base
{
private:
void DoFoo() // handler bazowy, zawsze wołany
{
cout << "Method from class 'Base' running..." << endl;
this->OnFoo();
}
protected:
virtual void OnFoo() { } // handler opcjonalny, wołane zawsze "najgłebsze" przeładowanie
public:
void RaiseFoo() { this->DoFoo(); } // wyzwalacz eventa
};
class Child : public Base
{
public:
virtual void OnFoo() { cout << "Hello I'm your child :)" << endl; }
};
class Grandchild : public Child
{
public:
virtual void OnFoo() { cout << "Hello I'm your grandchild :)" << endl; }
};
cout << "BASE:" << endl;
Base *base = new Base();
base->RaiseFoo();
cout << "CHILD:" << endl;
Base *child = new Child();
child->RaiseFoo();
cout << "GRANDCHILD:" << endl;
Base *grandchild = new Grandchild();
grandchild->RaiseFoo();
Wynik:
BASE:
Method from class 'Base' running...
CHILD:
Method from class 'Base' running...
Hello I'm your child :)
GRANDCHILD:
Method from class 'Base' running...
Hello I'm your grandchild :)