wesley
11th March 2009, 15:14
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 ?
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 ?