Lynx-9500设备Qt5.12+Tslib触摸异常问题求助
触摸异常:Qt5.12+Tslib按钮槽函数无法重复触发
在Lynx-9500 SLS设备上,通过工具链交叉编译了集成Tslib的Qt5.12库,编译过程无异常。但创建简单QWidget测试触摸屏幕时,触摸功能表现异常:按钮的槽函数无法被重复触发。已确认触摸硬件本身正常,且在非Qt应用中可正常工作。
Qt交叉编译配置
This is the Qt Open Source Edition. You have already accepted the terms of the Open Source license. Running configuration tests... Checking for gold linker... no Checking for C++1z support... no Checking for udev... no Checking for RDRAND instruction... no Checking for -Bsymbolic-functions support... no Checking for getentropy()... no Checking for ICU... no Checking for renameat2()... no Checking for slog2... no Checking for statx() in libc... no Checking for DoubleConversion... no Checking for PCRE2... no Checking for KMS... no Checking for OpenVG... no Checking for GBM... no Checking for mtdev... no Checking for HarfBuzz... no Checking for Vulkan... no Checking for XLib... no Checking for xkbcommon >= 0.5.0... no Checking for DB2 (IBM)... no Checking for InterBase... no Checking for MySQL... no Checking for OCI (Oracle)... no Checking for ODBC... no Checking for PostgreSQL... no Checking for SQLite (version 2)... no Checking for TDS (Sybase)... no Checking for jasper... no Checking for mng... no Checking for tiff... no Checking for webp... no Checking for Wayland client library... no Checking for Wayland EGL library... no Checking for wayland-server... no Checking for sensorfw... no Checking for Gypsy... no Checking for WinRT Geolocation API... no Checking for GStreamer 1.0... no Checking for GStreamer 0.10... no Checking for OpenAL... no Checking for PulseAudio >= 0.9.10... no Checking for libresourceqt5... no Checking for libclang... no Done running configuration tests. Configure summary: Building on: linux-g++ (x86_64, CPU features: mmx sse sse2) Building for: linux-arm-gnueabi-g++ (arm, CPU features: <none>) Target compiler: gcc 4.9.4 Configuration: cross_compile compile_examples enable_new_dtags largefile precompile_header shared rpath release c++11 c++14 concurrent reduce_exports stl Build options: Mode ................................... release Optimize release build for size ........ no Building shared libraries .............. yes Using C standard ....................... C11 Using C++ standard ..................... C++14 Using ccache ........................... no Using gold linker ...................... no Using new DTAGS ........................ yes Using precompiled headers .............. yes Using LTCG ............................. no Target compiler supports: NEON ................................. no Build parts ............................ libs Qt modules and options: Qt Concurrent .......................... yes Qt D-Bus ............................... no Qt D-Bus directly linked to libdbus .... no Qt Gui ................................. yes Qt Network ............................. yes Qt Sql ................................. yes Qt Testlib ............................. yes Qt Widgets ............................. yes Qt Xml ................................. yes Support enabled for: Using pkg-config ....................... yes udev ................................... no Using system zlib ...................... no Qt Core: DoubleConversion ....................... yes Using system DoubleConversion ........ no GLib ................................... no iconv .................................. yes ICU .................................... no Tracing backend ........................ <none> Logging backends: journald ............................. no syslog ............................... no slog2 ................................ no Using system PCRE2 ..................... no Qt Network: getifaddrs() ........................... yes IPv6 ifname ............................ yes libproxy ............................... no Linux AF_NETLINK ....................... yes OpenSSL ................................ yes Qt directly linked to OpenSSL ........ no OpenSSL 1.1 ............................ yes DTLS ................................... yes SCTP ................................... no Use system proxies ..................... yes Qt Gui: Accessibility .......................... yes FreeType ............................... yes Using system FreeType ................ yes HarfBuzz ............................... yes Using system HarfBuzz ................ no Fontconfig ............................. yes Image formats: GIF .................................. yes ICO .................................. yes JPEG ................................. yes Using system libjpeg ............... no PNG .................................. yes Using system libpng ................ no EGL .................................... no OpenVG ................................. no OpenGL: Desktop OpenGL ....................... no OpenGL ES 2.0 ........................ no OpenGL ES 3.0 ........................ no OpenGL ES 3.1 ........................ no OpenGL ES 3.2 ........................ no Vulkan ................................. no Session Management ..................... yes Features used by QPA backends: evdev .................................. yes libinput ............................... no INTEGRITY HID .......................... no mtdev .................................. no tslib .................................. yes xkbcommon .............................. no X11 specific: XLib ................................. no XCB Xlib ............................. no EGL on X11 ........................... no QPA backends: DirectFB ............................... no EGLFS .................................. no LinuxFB ................................ yes VNC .................................... yes Mir client ............................. no Qt Sql: SQL item models ........................ yes Qt Widgets: GTK+ ................................... no Styles ................................. Fusion Windows Qt PrintSupport: CUPS ................................... no Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite2 ................................ no SQLite ................................. yes Using system provided SQLite ......... no TDS (Sybase) ........................... no Qt Testlib: Tester for item models ................. yes Qt SerialBus: Socket CAN ............................. yes Socket CAN FD .......................... yes Further Image Formats: JasPer ................................. no MNG .................................... no TIFF ................................... yes Using system libtiff ................. no WEBP ................................... yes Using system libwebp ................. no Qt Wayland Client ........................ no Qt Wayland Compositor .................... no Qt Sensors: sensorfw ............................... no Qt Positioning: Gypsy GPS Daemon ....................... no WinRT Geolocation API .................. no Qt Location: Qt.labs.location experimental QML plugin . yes Geoservice plugins: OpenStreetMap ........................ yes HERE ................................. yes Esri ................................. yes Mapbox ............................... yes MapboxGL ............................. no Itemsoverlay ......................... yes QtXmlPatterns: XML schema support ..................... yes Qt Multimedia: ALSA ................................... yes GStreamer 1.0 .......................... no GStreamer 0.10 ......................... no Video for Linux ........................ yes OpenAL ................................. no PulseAudio ............................. no Resource Policy (libresourceqt5) ....... no Windows Audio Services ................. no DirectShow ............................. no Windows Media Foundation ............... no Qt Tools: QDoc ................................... no
配置中已明确启用Tslib。
目标设备运行环境变量(rc.local脚本)
# NOTE: The event num is changed when the USB barcode scanner is plugged in. if [ -e /dev/input/event3 ]; then echo "export TSLIB_TSDEVICE=/dev/input/event3" export TSLIB_TSDEVICE=/dev/input/event3 elif [ -e /dev/input/event2 ]; then echo "export TSLIB_TSDEVICE=/dev/input/event2" export TSLIB_TSDEVICE=/dev/input/event2 else echo "export TSLIB_TSDEVICE=/dev/input/event1" export TSLIB_TSDEVICE=/dev/input/event1 fi #QT VARIABLES export QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0 export QWS_MOUSE_PROTO=Tslib:/dev/input/event1 export QWS_KEYBOARD=linuxinput:/dev/input/event0
测试用QWidget代码
widget.h
#include <QWidget> class QPushButton; QT_BEGIN_NAMESPACE namespace Ui { class Widget; } QT_END_NAMESPACE class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); private: Ui::Widget *ui; QPushButton *btnBalance; private slots: void btnBalancePress(); }; #endif // WIDGET_H
widget.cpp
#include "widget.h" #include "ui_widget.h" #include "QPushButton" Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) { QPalette palette; palette.setBrush(this->backgroundRole(), QBrush(QImage(":/images/images/walpaper.bmp"))); this->setAutoFillBackground(true); this->setPalette(palette); QFont font; font.setPointSize(FONT_SIZE); font.setFamily(FONT_FAMILY); btnBalance = new QPushButton(this); btnBalance->setFont(font); btnBalance->setObjectName(QString::fromUtf8("btnBalance")); btnBalance->setText(QString::fromUtf8("button")); QObject::connect(btnBalance, SIGNAL(pressed()), this, SLOT(btnBalancePress())); } Widget::~Widget() { delete ui; } void Widget::btnBalancePress() { printf("btnBalancePress\n"); }
解决建议
- 清理Qt4遗留环境变量:Qt5采用QPA架构,不再使用QWS相关变量,删除
QWS_MOUSE_PROTO和QWS_KEYBOARD,避免与Qt5的触摸处理逻辑冲突。 - 统一触摸设备路径:确保
QT_QPA_GENERIC_PLUGINS使用的设备路径与TSLIB_TSDEVICE完全一致,保持脚本中的QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE即可,不要硬编码固定路径。 - 完成Tslib校准:在目标设备上执行
ts_calibrate完成触摸校准,未校准的触摸输入可能导致Qt无法正确识别重复点击事件。 - 替换按钮信号:将
pressed()信号替换为clicked()信号,clicked()需要按下并抬起才触发,更符合常规触摸交互逻辑,部分场景下pressed()可能因释放事件未正确传递导致无法重复触发。 - 调试触摸事件:重写事件过滤器,打印触摸事件类型,确认Qt是否接收到完整的按下/释放事件:
在widget.h中添加声明:
在widget.cpp中实现:protected: bool eventFilter(QObject *obj, QEvent *event) override;
并在构造函数中添加:bool Widget::eventFilter(QObject *obj, QEvent *event) { if (obj == btnBalance) { if (event->type() == QEvent::TouchBegin) { printf("Touch begin on button\n"); } else if (event->type() == QEvent::TouchEnd) { printf("Touch end on button\n"); } } return QWidget::eventFilter(obj, event); }btnBalance->installEventFilter(this); - 检查插件加载状态:运行测试程序前设置
export QT_DEBUG_PLUGINS=1,查看终端输出,确认tslib插件是否成功加载,有无报错信息。
内容的提问来源于stack exchange,提问作者peacism
相关产品推荐
相关产品推荐

