my qt application is a console
how to catch the keyevent ?such as a hit key
thank you
my qt application is a console
how to catch the keyevent ?such as a hit key
thank you
You can install an event filter on QApplication, and catch the key hit events.
LINK
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
I just code it like this:
QCoreApplication *app = new QCoreApplication (argc, argv);
KeyBoardEvent kvt;
qApp->installEventFilter(&kvt);
--------------------------------------------------------------------------------------
KeyBoadEvent:
class KeyBoardEventublic QObject
{
public :
KeyBoardEvent()
{
}
bool eventFilter(QObject *o, QEvent *event)
{
qDebug()<<"sdfs";
}
bool event(QEvent *event)
{
qDebug()<<"sdfs";
return true;
}
~KeyBoardEvent()
{
}
void run()
{
}
};
just print a "sdfs" one time i hit any key but nothing hanppend
my mistake this will not work for QCoreApplication. (as nothing will send key event to QCoreApplication)
You need to read stdin explicitly using C / C++ calls fscanf(), cin directly from main (before entering event loop), or write a console reader thread (inherit QThread) and read the stdin in the thread and do the required.
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
I have no choice I read /dev/input/event1 my keyboard device
Thank you
Bookmarks