not able to sendevent from keyboard notification
-
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_OBJECTpublic:
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();
} -
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