2

我为 arm9 板编译了以下代码。每当我按下任何键时,都应该检测到该事件。按键.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");
}
}

按键.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

主文件

#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();
}

使用外部键盘。qt配置:

/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

板载:export QWS_KEYBOARD="LinuxInput:/dev/input/event0"

当我运行 cat /dev/input/event0 | hexdump 我能够收到按键的键码。但是当我运行可执行键盘时没有响应。我错过了什么吗?如果是这样,我还应该怎么做才能使键盘工作?

4

0 回答 0