Unsolved Recursiveness in "catch enter key" example?
-
Hello comunity,
Im learnig C++ and Qt.
Could someboydy help me to understand a paar lines in the "catch enter key" example? https://wiki.qt.io/How_to_catch_enter_keypart of code contains the next:
bool keyEnterReceiver::eventFilter(QObject* obj, QEvent* event) { if (event->type()==QEvent::KeyPress) { QKeyEvent* key = static_cast<QKeyEvent*>(event); if ( (key->key()==Qt::Key_Enter) || (key->key()==Qt::Key_Return) ) { //Enter or return was pressed } else { return QObject::eventFilter(obj, event); //<- here is the question } return true; } else { return QObject::eventFilter(obj, event); //<- and here X-D } return false; }
I suppose that the call "return QObject::eventFilter(obj, event);" is recursiveness, when right... Why?, Which is the purpose of that and not return false?? Why is not an infinite loop?
thanks in advance.
-
@Josz said in Recursiveness in "catch enter key" example?:
I suppose that the call "return QObject::eventFilter(obj, event);" is recursiveness, when right... Why?
Nope. This is delegating the call to the parent's implementation[1]. It's done whenever you don't care about the event, so you allow the parent class to (maybe) process it.
[1] https://www.oreilly.com/library/view/c-cookbook/0596007612/ch08s16.html
-
@kshegunov Thank you very much
-
You're welcome!