Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Do I need to call installEventFilter(this)?
Forum Updated to NodeBB v4.3 + New Features

Do I need to call installEventFilter(this)?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 700 Views 1 Watching
  • 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.
  • JobRecrdJ Offline
    JobRecrdJ Offline
    JobRecrd
    wrote on last edited by
    #1

    Will the filter for this install itself? I tried it, it works in both cases, but I couldn't find any information about self-setting of the filter in the documentation.

    class MyClass : public QObject
    {
        Q_OBJECT
        MyClass()
        {
            installEventFilter(this); //Do I need this?
        }
    
    protected:
        bool eventFilter(QObject*, QEvent*) override
        {
            
        }
    };
    
    JonBJ 1 Reply Last reply
    0
    • JobRecrdJ JobRecrd

      @raven-worx
      That is, installEventFilter allows you to handle events before they arrive in the overridden eventFilter class method?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #6

      @JobRecrd
      No, installEventFilter sends the events to the eventFilter in the first place. From there you can optionally handle them, or you can just use it to choose to ignore some events while allowing others through for standard processing.

      1 Reply Last reply
      1
      • JobRecrdJ JobRecrd

        Will the filter for this install itself? I tried it, it works in both cases, but I couldn't find any information about self-setting of the filter in the documentation.

        class MyClass : public QObject
        {
            Q_OBJECT
            MyClass()
            {
                installEventFilter(this); //Do I need this?
            }
        
        protected:
            bool eventFilter(QObject*, QEvent*) override
            {
                
            }
        };
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @JobRecrd
        Yes it will "install for itself" with this code. "Do I need this?" You do not need it, but you can do it if you want to filter yourself.

        JobRecrdJ 1 Reply Last reply
        1
        • JonBJ JonB

          @JobRecrd
          Yes it will "install for itself" with this code. "Do I need this?" You do not need it, but you can do it if you want to filter yourself.

          JobRecrdJ Offline
          JobRecrdJ Offline
          JobRecrd
          wrote on last edited by
          #3

          @JonB
          Can you explain why it will be installed for itself? I don't really understand what will change when adding installEventFilter in this case.

          raven-worxR 1 Reply Last reply
          0
          • JobRecrdJ JobRecrd

            @JonB
            Can you explain why it will be installed for itself? I don't really understand what will change when adding installEventFilter in this case.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #4

            @JobRecrd
            you could inspect all events before they are actually processed in the event handlers.
            Buts its better practice to override the corresponding event handlers or even the generic event() method instead of doing it this way.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            JobRecrdJ 1 Reply Last reply
            2
            • raven-worxR raven-worx

              @JobRecrd
              you could inspect all events before they are actually processed in the event handlers.
              Buts its better practice to override the corresponding event handlers or even the generic event() method instead of doing it this way.

              JobRecrdJ Offline
              JobRecrdJ Offline
              JobRecrd
              wrote on last edited by
              #5

              @raven-worx
              That is, installEventFilter allows you to handle events before they arrive in the overridden eventFilter class method?

              JonBJ 1 Reply Last reply
              0
              • JobRecrdJ JobRecrd

                @raven-worx
                That is, installEventFilter allows you to handle events before they arrive in the overridden eventFilter class method?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #6

                @JobRecrd
                No, installEventFilter sends the events to the eventFilter in the first place. From there you can optionally handle them, or you can just use it to choose to ignore some events while allowing others through for standard processing.

                1 Reply Last reply
                1

                • Login

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