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. EventFilter show events returned
Forum Update on Monday, May 27th 2025

EventFilter show events returned

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.9k 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.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by A Former User
    #1

    Hi i put the class eventfilter but how i can show in the main of my program the events of this filter. Class:

    class FiltroDeEventosPersonalizado
      : public QObject
    {
      Q_OBJECT
    
    protected:
    
      bool eventFilter(QObject *obj, QEvent *event) override;
    };
    Method :
    bool
    FiltroDeEventosPersonalizado::eventFilter(
        QObject *obj,
        QEvent *event)
    {
      if (event->type() == QEvent::KeyPress) {
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        if( keyEvent->key() == Qt::Key_A )
         qDebug() << "Tecla 'A' presionada";
        return true;
      }
    
      return QObject::eventFilter(obj, event);
    }
    Main of my program:
    #include <QCoreApplication>
    #include <filtrodeeventospersonalizado.h>
    #include <QDebug>
    
    // main of my program ! -xd
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        //i want show the events with Qdebug
        return a.exec();
    }
    

    Edit: Added code tags -- @Wieland

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Im not 100% sure what you hope to catch as your code seems to lack a mainwindow?

      http://doc.qt.io/qt-5/qobject.html#installEventFilter

      so
      maybe
      a.installEventFilter( new FiltroDeEventosPersonalizado() );

      1 Reply Last reply
      1
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        Hi! This posting of mine shows an example use of an application global event filter: https://forum.qt.io/topic/71813/qwidget-objects-with-qt-window-flag-set-do-not-pass-on-ignored-events/3

        BTW: Please use markup for source code inside your postings (three backticks). Also, once your problem is solved, please mark it as solved instead of deleting it (see Hitchhiker's Visual Guide to the Qt Forum).

        RIVOPICOR 1 Reply Last reply
        4
        • ? A Former User

          Hi! This posting of mine shows an example use of an application global event filter: https://forum.qt.io/topic/71813/qwidget-objects-with-qt-window-flag-set-do-not-pass-on-ignored-events/3

          BTW: Please use markup for source code inside your postings (three backticks). Also, once your problem is solved, please mark it as solved instead of deleting it (see Hitchhiker's Visual Guide to the Qt Forum).

          RIVOPICOR Offline
          RIVOPICOR Offline
          RIVOPICO
          wrote on last edited by
          #4

          @Wieland One question about this with eventfilter i can capture the events and filter them. But if for example i want to create one application to save all events pressed in my computer. It's necessary to use a Hook. Thx a lot for your answer and i vote sorry i forgot.

          ? 1 Reply Last reply
          1
          • RIVOPICOR RIVOPICO

            @Wieland One question about this with eventfilter i can capture the events and filter them. But if for example i want to create one application to save all events pressed in my computer. It's necessary to use a Hook. Thx a lot for your answer and i vote sorry i forgot.

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @RIVOPICO You mean like in spyware?

            RIVOPICOR 1 Reply Last reply
            2
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Or automation software :)
              https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx

              1 Reply Last reply
              2
              • ? A Former User

                @RIVOPICO You mean like in spyware?

                RIVOPICOR Offline
                RIVOPICOR Offline
                RIVOPICO
                wrote on last edited by
                #7

                @Wieland I mean like one program to capture the keystrokes of my computer. All things that i am writting. All people recommend me use windows hook using windows API

                1 Reply Last reply
                0
                • RIVOPICOR Offline
                  RIVOPICOR Offline
                  RIVOPICO
                  wrote on last edited by RIVOPICO
                  #8

                  @Wieland And so if i am using Mac i coudnt save my keystrokes. ? In linux for example i can.
                  thx. Specify i could see some programs in linux and windows since store to register your activity nothing more.

                  ? 1 Reply Last reply
                  0
                  • RIVOPICOR RIVOPICO

                    @Wieland And so if i am using Mac i coudnt save my keystrokes. ? In linux for example i can.
                    thx. Specify i could see some programs in linux and windows since store to register your activity nothing more.

                    ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #9

                    @RIVOPICO I don't understand what you mean. What I meant to say was that you need to use the Windows API to capture all keyboard input on the machine. I don't know how this works on Linux. I guess you can get the key strokes from the X server (with proper access rights), or maybe from the window manager. Or maybe from the input's device file, IDK. Also I have no idea how it would be done on macOS.

                    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