Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Recursiveness in "catch enter key" example?

Recursiveness in "catch enter key" example?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
4 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Josz
    wrote on last edited by
    #1

    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_key

    part 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.

    kshegunovK 1 Reply Last reply
    0
    • J Josz

      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_key

      part 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.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @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

      Read and abide by the Qt Code of Conduct

      J 1 Reply Last reply
      3
      • kshegunovK kshegunov

        @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

        J Offline
        J Offline
        Josz
        wrote on last edited by
        #3

        @kshegunov Thank you very much

        kshegunovK 1 Reply Last reply
        0
        • J Josz

          @kshegunov Thank you very much

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          You're welcome!

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved