您的位置:首页 > 编程语言 > Qt开发

qt4.8.4 使用键盘后终端没有反映

2015-08-31 16:30 633 查看
今天遇到点奇怪的事情,自己写的程序需要通过键盘输入,我记得以前用Qt的时候,不需要增加什么环境变量,就可以直接使用键盘。但是今天不行了。于是在环境配置文件中加入了export QWS_KEYBOARD=LinuxInput:/dev/input/event3,这样一段。发现嗯,键盘可以用了,还小高兴了一下。但是没高兴一会,就笑不出来了,为什么ctrl+C不好使了呢!?于是在程序里面使用qDebug输出试一下,也没有输出

。囊袋死噶???

之后求助于万能的百度(其实相拥GOOGLE,奈何一直不会翻墙。会的同学教教我),找到了两篇文章:

        http://m.blog.csdn.net/blog/sddsighhz/42638461

        http://bbs.csdn.net/topics/390967543?page=1
文章中说需要修改Qt源码,即src/gui/embedded/qkbdlinuxinput.cpp文件。

#if 0
if (m_tty_fd >= 0) {
// save tty config for restore.
tcgetattr(m_tty_fd, &m_tty_attr);

struct ::termios termdata;
tcgetattr(m_tty_fd, &termdata);

// record the original mode so we can restore it again in the destructor.
::ioctl(m_tty_fd, KDGKBMODE, &m_orig_kbmode);

// setting this translation mode is even needed in INPUT mode to prevent
// the shell from also interpreting codes, if the process has a tty
// attached: e.g. Ctrl+C wouldn't copy, but kill the application.
::ioctl(m_tty_fd, KDSKBMODE, K_MEDIUMRAW);

// set the tty layer to pass-through
termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
termdata.c_oflag = 0;
termdata.c_cflag = CREAD | CS8;
termdata.c_lflag = 0;
termdata.c_cc[VTIME]=0;
termdata.c_cc[VMIN]=1;
cfsetispeed(&termdata, 9600);
cfsetospeed(&termdata, 9600);
tcsetattr(m_tty_fd, TCSANOW, &termdata);
}
#endif

按照如上方法,注释掉这部分代码。重新编译Qt(我只会全部重新编译,单独编译QtGui.so我不会),然后重新移植解可以了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Qt4.8.4 键盘无效 qt