查看完整版本: [-- 实在没办法了。。。求教嵌入式QT鼠标和键盘的设置 --]

QTCN开发网 -> Qt嵌入式开发 -> 实在没办法了。。。求教嵌入式QT鼠标和键盘的设置 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

flyleier 2017-03-03 11:50

实在没办法了。。。求教嵌入式QT鼠标和键盘的设置

小弟最近在做嵌入式QT的开发,但是鼠标不支持热插拔,就是如果在QT程序启动前插好鼠标,鼠标可以用,QT程序启动后,再插入鼠标,鼠标就不能用;键盘的大写无法锁定,就是Capslock灯已经亮了,但是在QT程序里面输入,还是小写的字符。鼠标和键盘都是USB的。
平台:IMX6
Qt版本:qt4.8.5
linux版本:3.0.35
如果各位大神有过之类经验的,望不吝赐教

大漠之鹰 2017-03-16 11:03
可以看一下鼠标键盘初始化的代码,最好单步调试一下,就可以看到问题

大漠之鹰 2017-03-17 09:31
QWSLinuxInputKbPrivate::QWSLinuxInputKbPrivate(QWSLinuxInputKeyboardHandler *h, const QString &device)
    : m_handler(h), m_fd(-1), m_tty_fd(-1), m_orig_kbmode(K_XLATE)
{
    setObjectName(QLatin1String("LinuxInputSubsystem Keyboard Handler"));

    QString dev = QLatin1String("/dev/input/event1");
    int repeat_delay = -1;
    int repeat_rate = -1;
    int grab = 0;

    QStringList args = device.split(QLatin1Char(':'));
    foreach (const QString &arg, args) {
        if (arg.startsWith(QLatin1String("repeat-delay=")))
            repeat_delay = arg.mid(13).toInt();
        else if (arg.startsWith(QLatin1String("repeat-rate=")))
            repeat_rate = arg.mid(12).toInt();
        else if (arg.startsWith(QLatin1String("grab=")))
            grab = arg.mid(5).toInt();
        else if (arg.startsWith(QLatin1String("/dev/")))
            dev = arg;
    }

    m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDWR, 0);
    if (m_fd >= 0) {
        ::ioctl(m_fd, EVIOCGRAB, grab);
        if (repeat_delay > 0 && repeat_rate > 0) {
            int kbdrep[2] = { repeat_delay, repeat_rate };
            ::ioctl(m_fd, EVIOCSREP, kbdrep);
        }

        QSocketNotifier *notifier;
        notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
        connect(notifier, SIGNAL(activated(int)), this, SLOT(readKeycode()));

        // play nice in case we are started from a shell (e.g. for debugging)
        m_tty_fd = isatty(0) ? 0 : -1;

        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);
        }
    } else {
        qWarning("Cannot open keyboard input device '%s': %s", qPrintable(dev), strerror(errno));
        return;
    }
}

调用流程是 app -> QWSServer::initServer -> QWSServer::openKeyboard() -> QKbdDriverFactory::create()

这是Qt的LinuxInput鼠标键盘打开过程,这是在QWSServer初始化的时候执行的,也就是在应用程序一开始就执行了,如果没有设备节点初始化鼠标键盘设备就会失败。因此不会支持热插拔。其它地方没有发现打开鼠标键盘设备的操作。你可以按照这个思路再跟一下,有时间我也看看,如果能改进一下QWSServer就更好了

flyleier 2017-03-23 09:04
大漠之鹰:QWSLinuxInputKbPrivate::QWSLinuxInputKbPrivate(QWSLinuxInputKeyboardHandler *h, const QString &device)
    : m_handler(h), m_fd(-1), m_tty_fd(-1), m_orig_kbmode(K_XLATE)
{
    setObjectName(QLatin1String("LinuxI .. (2017-03-17 09:31) 

谢谢回复,我看了这么多天,还是没有解决,我放弃了从Qt方面改了,看看从内核方便能不能解决这个问题。

wangmingxiao 2017-08-21 11:23
这个都是从内核驱动入手才对


查看完整版本: [-- 实在没办法了。。。求教嵌入式QT鼠标和键盘的设置 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled