Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. not able to sendevent from keyboard notification
Forum Updated to NodeBB v4.3 + New Features

not able to sendevent from keyboard notification

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
embeddedarmqkeyevent
2 Posts 2 Posters 1.6k 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.
  • ILI Offline
    ILI Offline
    IL
    wrote on last edited by
    #1

    Hi,
    I am still working on my target application beaglebone like.
    I try to pass my target keyboard notification into the QApplication.
    In my QT main class I override the virtual function void keyPressEvent(QKeyEvent)*
    I am tracking my application and everything is looking good except reaching the above function
    Also use:

    • SendEvent(receiver, QKeyEvent)
    • processEvent()
      please advice!

    My code looks like this:
    mainwindow.h file

    #include <QMainWindow>
    #include <QKeyEvent>

    namespace Ui {class PlatformApp;}

    class PlatformApp : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit PlatformApp(QWidget *parent);
    ~PlatformApp();
    void keyPressEvent(QKeyEvent *event);

    private slots:
    ...
    private:
    ...
    };

    mainwindow.cpp file

    PlatformApp::PlatformApp(QWidget *parent) :
    QMainWindow(parent), orientation(0),
    ui(new Ui::PlatformApp)
    {...}

    PlatformApp::~PlatformApp(){ delete ui;}

    void PlatformApp::keyPressEvent(QKeyEvent *event)
    {
    ... // NEVER GET INTO THIS FUNCTION!!!

         switch(event->key())
         {
         case Qt::Key_Enter:
            {
          ... // 
          break;
            }
            ...
            
            default:
            break;
         }
    

    QMainWindow::keyPressEvent(event);
    }

    hmimngr.h file - main application

    class QApplication;

    class CHmiMngr
    {
    public:
    CHmiMngr(...);
    ~CHmiMngr();
    ...

    private:
    QApplication* m_qtApplication;
    PlatformApp* m_qtMainWindow;
    };

    hmimngr.cpp file // main application

    CHmiMngr::CHmiMngr(ErrorCode &initStatus):
    m_osHelper(),
    m_kbdFd(0),
    m_qtApplication(0),
    m_qtMainWindow(0),
    {
    m_kbdFd = open(KBD_DEV_NAME_FULL, O_RDWR);
    if (m_kbdFd == -1)
    {
    initStatus = E_FAIL;
    return;
    }
    }

    CHmiMngr::~CHmiMngr(){}

    void CHmiMngr::initQtApplication()
    {
    m_qtApplication = new QApplication(argc,(Char**) &argv[0]);
    m_qtMainWindow = new PlatformApp(this);
    ...
    }

    void CHmiMngr::handleIncomingMsg(SEYOSEvent event)
    {
    if ((int)event.Data == m_kbdFd)
    {
    handleKeyBoard(event);
    }
    }

    void CHmiMngr::handleKeyBoard(SEYOSEvent event)
    {
    Int32 rxBytes = read(m_kbdFd,(void*)(&keyValue), 4);

    switch(keyValue)
    {
    case KBD_KEY_RIGHT / LEFT / UP / DOWN:
    {
    QObject* receiver = qobject_cast<QObject*>(m_qtMainWindow);

         QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_<somthing>, Qt::NoModifier);
         QApplication::sendEvent(receiver, &keyEvent);
      }
      break;
    

    ...

    QApplication::processEvents();
    }

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

      Hi,

      Because usually, it's the central widget of a QMainWindow that will have the keyboard focus thus get the keyPress/Release etc. events.

      You can put an event filter on that widget to do what you want.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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