Qt嵌入式触摸屏QMouseEvents未收到,直到MouseButtonRelease收到
Qt Embedded Touchscreen QMouseEvents Not Received Until MouseButtonRelease Received
我在一个带有触摸屏的小型ARM嵌入式Linux设备上使用Qt 4.8.3。我用tslib配置了我的触摸屏,并对其进行了校准,因此在/etc/中有一个点状文件。我的触摸事件的位置工作得很好,但无论如何,我在鼠标按下或鼠标释放事件之前获得鼠标移动的QEvent。此外,在我将手指从触摸屏上移开之前,我不会得到任何鼠标相关事件。我需要正常的行为,即我按下触摸屏并立即接收鼠标下降事件,然后是我的移动事件(如果有的话),然后是当我抬起手指时鼠标释放事件。
So what I'm seeing from the point of view of events received when I pressed down and then release looks like:
50 SockAct <-- Received right at press down
<-- NO Other events received until press released
<-- Now release by lifting finger from screen
50 SockAct <-- Immediately received a 50 ( SockAct ) and the rest of the events below:
2 <-- 2 == mouse down
2 <-- 2 == mouse down
3 <-- 3 == mouse release / up
3 <-- 3 == mouse release / up
77 <-- 77 == redraw
我还尝试通过实现以下qw74filter来查看QWS服务器事件,以观察进入我的QApplication的QWS事件:
/// For investigation mouse events
#include <QWSServer>
#include <QWSMouseHandler>
#include <QWSEvent>
bool GUIApp::qwsEventFilter(QWSEvent *e)
{
qDebug() << e->type;
if(e->type == QWSEvent::Mouse) {
QWSMouseHandler *curMouse = QWSServer::mouseHandler();
qDebug() << "mouse position is: " << curMouse->pos();
}
return false;
/*
QWSEvent::NoEvent 0 No event has occurred.
QWSEvent::Connected 1 An application has connected to the server.
QWSEvent::Mouse 2 A mouse button is pressed or released, or the mouse cursor is moved. See also Qt for Embedded Linux Pointer Handling.
*/
}
现在,当我启动我的应用程序时,我看到触摸屏幕后相同的行为-即打印以下内容:
2 <-- Nothing is printed until I release my finger from the screen!
mouse position is: QPoint(89,312)
2
mouse position is: QPoint(89,312)
正如你所看到的,当我松开我的手指时,我得到了2个事件,大概是按下并松开。
我在Linux的/dev/input/触摸屏设备上运行'evtest',当按下屏幕时,肯定会立即看到触屏事件。直到我抬起手指,我才得到鼠标释放事件,因此驱动程序的行为符合预期。当我按下时,也没有"重复"触地事件-它只是一次按下的一个事件,但行为正确。
我不知道为什么我看到我的行为。Qt和输入设备之间一定存在转换问题。
此外,如果我在处理我的MouseButtonRelease接收事件时添加了3毫秒的延迟,那么我就会得到应用程序如何工作的期望行为,但我仍然没有收到我的鼠标事件,直到我释放按键。我根本不应该添加延迟,我希望鼠标向下发生,然后是任何移动,最后依次发生鼠标向上事件
有谁知道如何解决这个问题或什么可能导致这个??非常感谢!
,
直到我真正抬起手指,我才看到下面的打印:
...
MOVE TYPE: 5
"Mouse move (382,129)"
MOUSE BUTTON PRESS TYPE: 2
"Mouse Button Press (1)"
MOUSE BUTTON RELEASE TYPE: 3
"Mouse Button Release (1)"
....
这是我的eventFilter,我检查我的应用程序中收到的事件:
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Just for kicks print out the mouse position
if (event->type() == QEvent::MouseButtonPress)
{
qDebug() << "MOUSE BUTTON PRESS TYPE: " << event->type();
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
qDebug() << QString("Mouse Button Press (%1)").arg(mouseEvent->button());
}
if (event->type() == QEvent::MouseMove)
{
qDebug() << "MOVE TYPE: " << event->type();
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
qDebug() << QString("Mouse move (%1,%2)").arg(mouseEvent->globalX()).arg(mouseEvent->globalY());
}
if (event->type() == QEvent::MouseButtonRelease)
{
qDebug() << "MOUSE BUTTON RELEASE TYPE: " << event->type();
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
delay();
qDebug() << QString("Mouse Button Release (%1)").arg(mouseEvent->button());
//return true; // Gobble the event
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
这是我的延迟函数:
void Monitor::delay()
{
QTime dieTime = QTime::currentTime().addMSecs(3);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
解决-我发现这个线程:https://github.com/kergoth/tslib/issues/10概述了同样的问题。这似乎是一个问题在Tslib与Atmel MXT Maxtouch驱动程序。注释掉ts.conf文件中的Variance模块解决了我的问题——我现在在触摸屏幕后立即得到鼠标按下事件。
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 为什么这个 std::queue/指向结构的指针列表直到 List.Size() == 0 才释放内存?
- 如何从文本文件中读取数值,直到遇到字符类型?
- C++运行直到按键
- 我正在尝试使用 while 循环从字符串中删除字母,直到没有字母。我在这里做错了什么?
- 当 getline 直到新行才读取时会发生什么?
- 如何反复调用函数直到满足模拟?
- 如何打印下一个字母直到 Z 并继续到 A?
- 为什么即使直到最后才定义实际类型,也可以将依赖名称视为完整
- 如何创建一个 while 循环,继续循环,直到在C++中输入'using streams'键?
- 需要从存档中读取一行文本.txt直到找到"hhh",然后转到下一行
- 打印质数直到 N 以 C++
- 读取二进制文件直到结束 c++
- 按升序打印矢量的所有元素直到它为空而没有重复项的最有效方法是什么?
- 擦除矢量中的所有元素,直到第一个非零元素C++
- 延迟函数使打开的框架窗口冻结,直到指定的时间过去
- 继续运行程序而无需任何干预,直到要求退出为止
- 越界成员函数定义是否需要一个完全限定的类名,直到全局范围
- C++-打印素数直到N
- 如何等待密钥事件,直到进程在 QT 中完成