在hisi3536环境下做开发,遇到了非常奇怪的现象,当鼠标滚轮在qt程序上快速滚动的时候,程序直接不接受鼠标事件了,包括鼠标的左右按钮,滚轮、移动等事件均无反应,最终查看qws底层鼠标模块代码,找到解决方案!
下面是所需要修改的代码。
修改1 retries由原来的2加大一些,可自己测试
void QWSPcMouseHandlerPrivate::readMouseData(int fd)
{
.....
if (any_reliable) {
qDebug("get rid of all unreliable ones? All bad ones?.");
// ... get rid of all unreliable ones? All bad ones?
} else if (retries < 10) {
qDebug("Try again - maybe the mouse was being moved when we tried to init.");
// Try again - maybe the mouse was being moved when we tried to init.
closeDevices();
openDevices();
retries++;
}
}
修改2 QWSPcMouseSubHandler
class QWSPcMouseSubHandler {
protected:
int fd;
.....
int badness;
int resetbadness; //添加变量
virtual int tryData()=0;
//添加下面三个对变量的方法
int getResetBadness(){return resetbadness;}
void initResetBadness(){resetbadness = 0;}
void addOneToRestBadness(){resetbadness +=1;}
int takeWheel() { int result = wheel; wheel = 0; return result; }
修改3 QWSPcMouseHandlerPrivate::sendEvent
bool QWSPcMouseHandlerPrivate::sendEvent(QWSPcMouseSubHandler& h)
{
qDebug("QWSPcMouseHandlerPrivate::sendEvent(QWSPcMouseSubHandler& h)");
if (h.reliable()) {
h.initResetBadness();
QPoint motion = h.takeMotion();
if (qAbs(motion.x()) > accel_limit || qAbs(motion.y()) > accel_limit)
motion *= accel;
QPoint newPos = handler->pos() + motion;
if (qt_screen->isTransformed()) {
QSize s = QSize(qt_screen->width(), qt_screen->height());
newPos = qt_screen->mapToDevice(newPos, s);
}
handler->limitToScreen(newPos);
qDebug("QWSPcMouseHandlerPrivate::sendEvent true");
handler->mouseChanged(newPos, h.buttonState(), h.takeWheel());
return true;
} else {
qDebug("QWSPcMouseHandlerPrivate::sendEvent false");
h.takeMotion();
h.addOneToRestBadness();
if(h.getResetBadness() > 50) //50 可以自己定义
{
qDebug("h.getResetBadness() > 50");
closeDevices();
openDevices();
return false;
}
if (h.buttonState() & (Qt::RightButton|Qt::MidButton)) {
// Strange for the user to press right or middle without
// a moving mouse!
h.worse();
}
return false;
}
}