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. Show with qdebug keyevent
Qt 6.11 is out! See what's new in the release blog

Show with qdebug keyevent

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k 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
    #1

    Hi i want to show my filter in my main function but i couldn't.

    ```
    

    Código filter.h:
    #ifndef FILTRODEEVENTOSPERSONALIZADO_H
    #define FILTRODEEVENTOSPERSONALIZADO_H

    #include <QObject>
    
    class FiltroDeEventosPersonalizado
      : public QObject
    {
      Q_OBJECT
    
    protected:
    
      bool eventFilter(QObject *obj, QEvent *event) override;
    };
    #endif // FILTRODEEVENTOSPERSONALIZADO_H
    
    
    Código filter.cpp:
    
        ```
    #include "filtrodeeventospersonalizado.h"
        #include <QEvent>
        #include <QDebug>
        #include <QKeyEvent>
        
        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:

    ```
    

    #include <QCoreApplication>
    #include <filtrodeeventospersonalizado.h>
    #include <QDebug>
    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    FiltroDeEventosPersonalizado *filtro = new FiltroDeEventosPersonalizado;
    a.installEventFilter(filtro);
    return a.exec();
    }

    Hi i only want to show since qdebug my key pressed A. thx
    raven-worxR 1 Reply Last reply
    0
    • RIVOPICOR RIVOPICO

      Hi i want to show my filter in my main function but i couldn't.

      ```
      

      Código filter.h:
      #ifndef FILTRODEEVENTOSPERSONALIZADO_H
      #define FILTRODEEVENTOSPERSONALIZADO_H

      #include <QObject>
      
      class FiltroDeEventosPersonalizado
        : public QObject
      {
        Q_OBJECT
      
      protected:
      
        bool eventFilter(QObject *obj, QEvent *event) override;
      };
      #endif // FILTRODEEVENTOSPERSONALIZADO_H
      
      
      Código filter.cpp:
      
          ```
      #include "filtrodeeventospersonalizado.h"
          #include <QEvent>
          #include <QDebug>
          #include <QKeyEvent>
          
          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:

      ```
      

      #include <QCoreApplication>
      #include <filtrodeeventospersonalizado.h>
      #include <QDebug>
      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);
      FiltroDeEventosPersonalizado *filtro = new FiltroDeEventosPersonalizado;
      a.installEventFilter(filtro);
      return a.exec();
      }

      Hi i only want to show since qdebug my key pressed A. thx
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @RIVOPICO
      if thats all the code you are using, then maybe it is caused by the fact that there is no widget/window which would receive the key event.

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

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

        @RIVOPICO
        if thats all the code you are using, then maybe it is caused by the fact that there is no widget/window which would receive the key event.

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

        @raven-worx but i can't show the event? with qdebug?

        raven-worxR 1 Reply Last reply
        0
        • RIVOPICOR RIVOPICO

          @raven-worx but i can't show the event? with qdebug?

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

          @RIVOPICO
          as i said: there is no key event when there is no window to receive it.
          Create one and it should work as expected.

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

          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