2

i compiled the following code for arm9 board. whenever i press any key the event should be detected. keypress.ccp:

#include "keypress.h"

#include <QApplication>
#include <QKeyEvent>

KeyPress::KeyPress(QWidget *parent) :
QWidget(parent)
{
myLabel = new QLabel("LABEL");
mainLayout = new QVBoxLayout;
mainLayout->addWidget(myLabel);
setLayout(mainLayout);

}

void KeyPress::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_A)
{
    myLabel->setText("You pressed A");
}
}

void KeyPress::keyReleaseEvent(QKeyEvent *event)
{
 if(event->key())
{
    qDebug()<<"key released";
}

if(event->key() == Qt::Key_A)
{
    myLabel->setText("You released A");
}
}

keypress.h:

#ifndef KEYPRESS_H
#define KEYPRESS_H

#include <QWidget>
#include <QtGui>

class KeyPress : public QWidget
{
Q_OBJECT
public:
KeyPress(QWidget *parent = 0);

protected:
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);

private:
QLabel *myLabel;
QVBoxLayout *mainLayout;
};

#endif // KEYPRESS_H

main.cpp

#include <QtGui>
#include "keypress.h"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qDebug()<<"test";
KeyPress *keyPress = new KeyPress();
keyPress->show();

return a.exec();
}

using external key pad. qt configuration:

/configure -embedded arm -xplatform qws/linux-arm-gnueabi-g++ -little-endian -qt-gfx-linuxfb -qt-gfx-qvfb -qt-kbd-tty -qt-kbd-qvfb -qt-kbd-linuxinput -qt-mouse-linuxinput -qt-mouse-qvfb -qt-mouse-pc -declarative -confirm-license

on board: export QWS_KEYBOARD="LinuxInput:/dev/input/event0"

when i run cat /dev/input/event0 | hexdump i am able to recieve keycodes for the key pressed. but when i run the the executable keypad is not responding. am i missing something? if so what else i should do to make the keypad work??

geek
  • 794
  • 3
  • 16
  • 41

0 Answers0