PDA

View Full Version : Qt Embedded Linux - QWSKeyboardHandler



zuck
13th May 2009, 16:04
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.



pkFingerPrintManager::pkFingerPrintManager()
: QWSKeyboardHandler()
{
QWSServer::setKeyboardHandler(this);
}

// ... 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:



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?

wysota
14th May 2009, 02:23
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.

zuck
14th May 2009, 17:09
I'm using "grabKeyboard" method to connect all key events to its parent widget. On my x86 machine it works.

zuck
15th May 2009, 17:50
I've added these lines to my QApplication (server) instance:



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 :(

wysota
15th May 2009, 17:56
Did you do what I suggested?

zuck
18th May 2009, 14:53
Yes, as I've already said, I've created a keyoboard event filter in the QWSServer instance but it's never invoked...

wysota
18th May 2009, 20:12
That's not what I told you to do... And I see you didn't even read the docs of a method you used:

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.

zuck
19th May 2009, 17:53
You're right, I'm sorry.

Well, I've added an event filter to my QApplication instance:



class KeyPressEater : public QObject
{
Q_OBJECT

public:
KeyPressEater() : QObject(0) {};
virtual ~KeyPressEater() {};

protected:
bool eventFilter(QObject *obj, QEvent *event);
};

bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
{
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.

wysota
19th May 2009, 20:43
On both x86 and ARM?

zuck
20th May 2009, 14:53
No, on the x86 platform all key events are correctly received and printed by the qDebug statement.

wysota
20th May 2009, 19:05
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.

zuck
21st May 2009, 14:46
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?

wysota
21st May 2009, 22:45
Don't ask me. I'm just looking at the API.