Qt Embedded Linux - QWSKeyboardHandler
Hi!
We're using a biometric sensor as input device for an embedded project.
I've created a QWSKeyboardHandler derived class which sends some key press events to the QWSServer instance. It uses the QWSKeyboardHandler::processKeyEvent method to send all key press events.
Code:
pkFingerPrintManager::pkFingerPrintManager()
{
}
// ... CUT ...
void pkFingerPrintManager::notifyInputEvent(int dx, int dy, int state)
{
if (this->isNavigateRunning())
{
m_dx += dx;
m_dy += dy;
if (m_dx >= PK_FPM_KEY_THRESHOLD)
{
this
->processKeyEvent
(QEvent::KeyPress, Qt
::Key_Right,
0,
true,
false);
m_dx = 0;
}
if (m_dx <= -PK_FPM_KEY_THRESHOLD)
{
this
->processKeyEvent
(QEvent::KeyPress, Qt
::Key_Left,
0,
true,
false);
m_dx = 0;
}
if (m_dy >= PK_FPM_KEY_THRESHOLD)
{
this
->processKeyEvent
(QEvent::KeyPress, Qt
::Key_Down,
0,
true,
false);
m_dy = 0;
}
if (m_dy <= -PK_FPM_KEY_THRESHOLD)
{
this
->processKeyEvent
(QEvent::KeyPress, Qt
::Key_Up,
0,
true,
false);
m_dy = 0;
}
if (dx == 0)
m_dx = 0;
if (dy == 0)
m_dy = 0;
}
}
On my test machine (Linux x86) everything works.
Now we are testing it on the final ARM-based architecture but no key event is sent (or received). The process flow enters in one of the four "if" statements but the test widget doesn't receive any events.
This is the test widget "keyPressEvent" filter body:
Code:
void TestWidget
::keyPressEvent(QKeyEvent* event
) {
if (event->key() == Qt::Key_Left)
{
// ...
event->accept();
return;
}
if (event->key() == Qt::Key_Right)
{
// ...
event->accept();
return;
}
// ...
event->ignore();
}
Could you help me to find the problem, please?
Re: Qt Embedded Linux - QWSKeyboardHandler
Maybe the problem is not in the keyboard handler? Are you sure your widget has keyboard focus? You could try applying an event filter on the application object and see if the events are delivered to the application at all.
Re: Qt Embedded Linux - QWSKeyboardHandler
I'm using "grabKeyboard" method to connect all key events to its parent widget. On my x86 machine it works.
Re: Qt Embedded Linux - QWSKeyboardHandler
I've added these lines to my QApplication (server) instance:
Code:
class MyKeyboardFilter : public KeyboardFilter
{
public:
bool filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)
{
qDebug() << unicode << keycode << isPress;
return false;
}
}
// ... CUT ...
qwsServer->addKeyboardFilter(new MyKeyboardFilter());
qwsServer
->sendKeyEvent
(QEvent::KeyPress, Qt
::Key_Up,
0,
true,
false);
but the "filter" method is never called :(
Re: Qt Embedded Linux - QWSKeyboardHandler
Did you do what I suggested?
Re: Qt Embedded Linux - QWSKeyboardHandler
Yes, as I've already said, I've created a keyoboard event filter in the QWSServer instance but it's never invoked...
Re: Qt Embedded Linux - QWSKeyboardHandler
That's not what I told you to do... And I see you didn't even read the docs of a method you used:
Quote:
Note that the filter is not invoked for keys generated by virtual keyboard drivers (i.e., events sent using the sendKeyEvent() function).
I told you to install an event filter on the application object and not to set a keyboard filter on the server object.
Re: Qt Embedded Linux - QWSKeyboardHandler
You're right, I'm sorry.
Well, I've added an event filter to my QApplication instance:
Code:
class KeyPressEater
: public QObject{
Q_OBJECT
public:
virtual ~KeyPressEater() {};
protected:
};
{
qDebug() << event->type();
if (event
->type
() == QEvent::KeyPress) {
QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
qDebug("Key press %d", keyEvent->key());
return false;
} else {
// standard event processing
return QObject::eventFilter(obj, event
);
}
}
// In QApplication code:
this->installEventFilter(new KeyPressEater());
No key press event is received by my QApplication object.
Re: Qt Embedded Linux - QWSKeyboardHandler
Re: Qt Embedded Linux - QWSKeyboardHandler
No, on the x86 platform all key events are correctly received and printed by the qDebug statement.
Re: Qt Embedded Linux - QWSKeyboardHandler
The first argument of processKeyEvent() is wrong. It should contain the unicode value of the key, not QEvent::KeyPress. Also make sure if the constructor of your subclass is called at all.
Re: Qt Embedded Linux - QWSKeyboardHandler
Quote:
Originally Posted by
wysota
The first argument of processKeyEvent() is wrong. It should contain the unicode value of the key, not QEvent::KeyPress...
I'm a bit confused :confused: Why I need to specify both unicode and key code?
Re: Qt Embedded Linux - QWSKeyboardHandler
Don't ask me. I'm just looking at the API.