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. Problem with QKeyEvent
Forum Update on Monday, May 27th 2025

Problem with QKeyEvent

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • L Offline
    L Offline
    lbrycht
    wrote on last edited by
    #1

    Hello,

    I design an application where I will not have access to the system keyboard. It is for this key panel monitor connected via RS232. The buttons have to simulate the keys Tab, Backtab, arrows and Enter.
    In the class of the main dialog , I emit signals corresponding buttons, ie.

    if (key == KEY_TAB)
    {
        emit KeyPressTab ();
    }
    

    This signal is captured in the various dialog boxes by using the call:

    QObject :: connect (mainwindow, SIGNAL (KeyPressTab ()), this, SLOT (OnKeyPressTab ()));
    

    In turn, the same function slot is:

    void SecondDialog :: OnKeyPressTab ()
    {
        QKeyEvent event (QEvent :: KeyPress, Qt :: Key_Tab, Qt :: NoModifier);
        QApplication :: sendEvent (this, & event);
    }
    

    In this way, tabulation and BackTab works without a problem, but the arrow and enter not work.
    I am using the same mechanism, such as:

    ------------------------------- ----------------- Main Window ------------
    if (key == KEY_TAB)
        emit KeyPressLeft ();
    
    ------------------------------- ----------------- Second Dialog-----------
    QObject :: connect (mainwindow, SIGNAL (KeyPressLeft ()), this, SLOT (OnKeyPressLeft ()));
    
    void SecondDialog:: OnKeyPressLeft ()
    {
        QKeyEvent event (QEvent :: KeyPress, Qt :: KEY_LEFT, Qt :: NoModifier);
        QApplication :: sendEvent (this, & event);
    }
    

    Unfortunately, no reaction.
    Please help.

    raven-worxR 1 Reply Last reply
    0
    • L lbrycht

      Hello,

      I design an application where I will not have access to the system keyboard. It is for this key panel monitor connected via RS232. The buttons have to simulate the keys Tab, Backtab, arrows and Enter.
      In the class of the main dialog , I emit signals corresponding buttons, ie.

      if (key == KEY_TAB)
      {
          emit KeyPressTab ();
      }
      

      This signal is captured in the various dialog boxes by using the call:

      QObject :: connect (mainwindow, SIGNAL (KeyPressTab ()), this, SLOT (OnKeyPressTab ()));
      

      In turn, the same function slot is:

      void SecondDialog :: OnKeyPressTab ()
      {
          QKeyEvent event (QEvent :: KeyPress, Qt :: Key_Tab, Qt :: NoModifier);
          QApplication :: sendEvent (this, & event);
      }
      

      In this way, tabulation and BackTab works without a problem, but the arrow and enter not work.
      I am using the same mechanism, such as:

      ------------------------------- ----------------- Main Window ------------
      if (key == KEY_TAB)
          emit KeyPressLeft ();
      
      ------------------------------- ----------------- Second Dialog-----------
      QObject :: connect (mainwindow, SIGNAL (KeyPressLeft ()), this, SLOT (OnKeyPressLeft ()));
      
      void SecondDialog:: OnKeyPressLeft ()
      {
          QKeyEvent event (QEvent :: KeyPress, Qt :: KEY_LEFT, Qt :: NoModifier);
          QApplication :: sendEvent (this, & event);
      }
      

      Unfortunately, no reaction.
      Please help.

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

      @lbrycht
      how/where do you check the key event?
      If you are doing it in the dialog base-class i guess the focus widget is "swallowing/consuming the key event and thus it's not propagated up to the dialog.

      You should use qApp->installEventFilter() and filter the key events there (maybe check if the receiver QObject is inside your dialog - before they are send to the focus widget.

      --- 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
      • L Offline
        L Offline
        lbrycht
        wrote on last edited by lbrycht
        #3

        The events pressing the keys of the external keyboard are handled in a separate process (writing under Debian). In the main class of the program Qt, I have a receiving thread and using mutex_trylock and mutex_unclock. Receiving data drom an external keyboard works correctly.

        I am surprised that the keys Tab and Backtab work properly and the other did not respond.

        I'll try to use the filtering mechanism of events with

        App->installEventFilter()
        

        For clarification I posted algorithm below.
        https://imagizer.imageshack.us/v2/749x623q90/921/RhKKOx.jpg

        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