0
我有一個非常簡單的Qt 4.8.4嵌入式Linux應用程序,可以在ARM上運行。它基本上只是在qApp級別安裝了一個eventFilter。我的電路板上有一個電源按鈕,按下時會發出'代碼116(電源)'。Qt 4.8.4嵌入式Linux句柄電源按鍵按
下面是evtest輸出:
# ./evtest /dev/input/event2
Input driver version is 1.0.1
Input device ID: bus 0x0 vendor 0x0 product 0x0 version 0x0
Input device name: "twl4030_pwrbutton"
Supported events:
Event type 0 (Sync)
Event type 1 (Key)
Event code 116 (Power)
Testing ... (interrupt to exit)
Event: time 1370431888.296539, type 1 (Key), code 116 (Power), value 1
Event: time 1370431888.296539, -------------- Report Sync ------------
Event: time 1370431888.453338, type 1 (Key), code 116 (Power), value 0
Event: time 1370431888.453338, -------------- Report Sync ------------
Event: time 1370431890.855651, type 1 (Key), code 116 (Power), value 1
Event: time 1370431890.855682, -------------- Report Sync ------------
Event: time 1370431891.026885, type 1 (Key), code 116 (Power), value 0
Event: time 1370431891.026885, -------------- Report Sync ------------
每次我按下按鈕,我得到一些輸出:
# cat platform-omap_i2c.1-platform-twl4030_pwrbutton-event
�#�Qwat�#�Qwa�#�QY= t�#�QY=
我啓動我的應用程序「-qws」我eventFilter是印刷每一個事件我的Qt應用程序得到:
// Install the event filter
bool TestApp::eventFilter(QObject *obj, QEvent *ev) {
qDebug() << ev->type();
事件過濾器獲取其他觸摸和按鍵事件,但從來沒有(116)電源。那麼如何讓Qt應用程序從Linux接收此事件?謝謝!
UPDATE:
我也實現了一個過濾器,會攔截並報告了Qt QWS服務器接收到的所有事件。這裏是我的頭文件:
#include <QApplication>
#include <QDebug>
/// The QWS embedded server for OS events
#include <QWSServer>
/// For investigation key events
#include <QWSServer>
#include <QWSMouseHandler>
#include <QWSEvent>
class Filter : public QApplication
{
public:
這是我實現:
#include "filter.h"
bool Filter::qwsEventFilter(QWSEvent *e)
{
qDebug() << "NEW TYPE: " << e->type;
}
Filter(int &argc, char **argv) : QApplication(argc, argv) {};
bool qwsEventFilter(QWSEvent * event);
};
而這裏的main.c:
#include <QApplication>
#include "filter.h"
int main(int argc, char *argv[])
{
Filter a(argc, argv);
return a.exec();
}
不過,我覺得,也許是QWS吞噬了電源按事件,但在做這個qwsFilter之後,我發現QWS根本沒有收到Power Events!