【问题标题】:Qt 4.8.4 Embedded Linux Handle Power Button Key PressQt 4.8.4 嵌入式 Linux 手柄电源按钮按键
【发布时间】:2013-06-05 11:43:54
【问题描述】:

我有一个在 ARM 上运行的非常简单的 Qt 4.8.4 嵌入式 Linux 应用程序。它基本上只是在 qApp 级别安装了一个 eventFilter。我的板上有一个电源按钮,按下时会发出“代码 116(电源)”。

这里是 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 接收这个事件呢?谢谢!

更新:

我还实现了一个过滤器,它将拦截并报告 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 根本没有接收到电源事件!

【问题讨论】:

    标签: linux qt user-input qtembedded


    【解决方案1】:

    实际上,将环境变量设置为正确的键盘输入可以让我捕获电源事件。

    这样做:

    export QWS_KEYBOARD=linuxinput:/dev/input/event2
    

    而不是这样:

    export QWS_KEYBOARD=linuxinput:/dev/input/keypad
    

    允许我捕捉和使用电源按钮。

    此外,您还可以像这样捕获多个输入:

    export QWS_KEYBOARD="linuxinput:/dev/input/keypad linuxinput:/dev/input/event2"
    

    【讨论】:

      猜你喜欢
      • 2018-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多