No keyboard events with QCoreApplication
Hi!
I'm running a simple command line application based on QCoreApplication and for some reason I am not receiving keyboard inputs. When in run this program in the command line on Linux using ./Application, I can see the keys that I press on the keyboard and but there is no reaction from the keyPressEvent. Can anyone point out where my mistake is?
Code:
int main(int argc, char *argv[])
{
Application w;
a.installEventFilter(&w);
return a.exec();
}
Code:
{
Q_OBJECT
public:
~Application();
protected:
};
void Application
::keyPressEvent(QKeyEvent *event
) {
qDebug() << "keyPressEvent event occured" << event; // This is never printed.
}
Re: No keyboard events with QCoreApplication
You need to add the protected method QObject::eventFilter() to your Application class instead of the keyPressEvent):
Code:
{
Q_OBJECT
public:
~Application();
protected:
};
{
if ( pEvent
->type
() == QEvent::KeyPress ) {
// got a key press
return true;
}
else
return QObject::eventFilter( pObj, pEvent
);
}
Because your current Application class implementation does not define this method, the base class QObject's method is called instead.