[Qt-embedded-interest] QSocketNotifier emit activated signal endlessly. why ?

wesley.xie wesley.xie at xmediatek.com
Thu Mar 12 02:34:06 CET 2009


please anyone here help me to solve this problem.

I am working on linux 2.4.19 (arm based) + qt-embedded-free-3.3.8b.
and now I am writing a custom keyboard handler which subclass from QWSKeyBoardHandler.

class MyKbdHandler: public QObject, public QWSKeyBoardHandler {
    Q_OBJECT
public:
    MyKbdHandler();
    ~MyKbdHandler();
 
private slots:
    void readKbdData();
 
private:
    QSocketNotifier *m_kbdNotifier;
    int m_kbdFd;
} 

MyKbdHandler::MyKbdHandler()
: QObject(), QWSKeyBoardHandler()
{
    m_kbdNotifier = NULL;
    m_kbdFd = ::open("/dev/input", O_RDONLY|O_NONBLOCK);
    if (m_kbdFd < 0) {
        qDebug("Can not open input device!\n");
        return;
    }
 
    m_kbdNotifier = new QSocketNotifier(m_kbdFd, QSocketNotifier::Read, this);
    connect(m_kbdNotifier, SIGNAL(activated(int)), this, SLOT(readKbdData()));
}
 
MyKbdHandler::~MyKbdHandler()
{
    if (m_kbdFd >= 0) {
        ::close(m_kbdFd);
        m_kbdFd = -1;
    }
 
    if (m_kbdNotifier != NULL) {
        delete m_kbdNotifier;
        m_kbdNotifier = NULL;
    }
}
 
MyKbdHandler::readKbdData()
{
    
    char buf[1024] = { 0 };
    int n = ::read(m_kbdFd, buf, sizeof(buf));
    qDebug("MyKbdHandler::readKbdData = %d\n", n);
 
    // do key code mapping and call processKeyEvent here ...
 
}

after reading all of the available data(the read call already return 0), the activated() signal emit over and over again, and readKbdData() also get invoked. the cpu reached to 98%.!

any idea ? 

/WX
-- 
此电子邮件内容已经被 MailScanner 扫描.且被视为是无毒的.
MailScanner 感谢 transtec Computers 的大力支援.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-embedded-interest/attachments/20090312/c9ba0943/attachment.html 


More information about the Qt-embedded-interest mailing list