balasaravanan
9th November 2011, 05:42
Hi All,
I have implemented a QT Key board plugin similar to the one given in Qt documentation
void QWSInputKbPrivate::readKeycode()
{
KEY_EVENT key[MAX_EVENTS_TO_READ];
int digit;
int events,current=0;
KEYPAD_KEYS keypad_key;
int pressed;
int keycode, unicode;
events = QT_READ(m_fd, reinterpret_cast<char *>(&key), MAX_EVENTS_TO_READ*sizeof(KEY_EVENT)) / sizeof(KEY_EVENT) ;
while (events!=current) {
keypad_key=digitToKeyArr[ key[current].column][key[current].row ];
pressed=key[current].key_press_time;
keycode = keysToQTArr[keypad_key].keycode;
unicode = keysToQTArr[keypad_key].unicode;
printf("readKeycode ---> key: %d press=%d, keycode=%d, unicode=%x %c\n", keypad_key, pressed, keycode, unicode, unicode);
m_handler->processKeyEvent(unicode, keycode, Qt::NoModifier, false, false);
current ++ ;
}
}
I am able to compile the key board plugin. I am able to set the QWS_KEYBOARD variable to this kbd plugin name. When starting an Qt application as server/client, the above printf function gets executed. So i understand that the character input hardware device is opened successfully and it is read correctly.
In the application, I have a single class deriving from QWidget. I create a instance of this class in the main program and show() it. This DiallerForm contains a single QLineEdit widget to get user input from key pad.
class DiallerForm : public QWidget
{
Q_OBJECT
public:
DiallerForm();
private slots:
void keyPressEvent(QKeyEvent *event);
bool event(QEvent *event);
private:
Ui::DiallerForm ui;
};
void DiallerForm::keyPressEvent(QKeyEvent *event) {
printf("DiallerForm::keyPressEvent \n");
}
bool DiallerForm::event(QEvent *event) {
switch(event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease:
printf("DiallerForm::event - key press \n");
break;
default:
break;
}
return QWidget::event(event);
}
The main() code is something like this
int main(int argc, char **argv)
{
QApplication app(argc,argv);
DiallerForm *df = new DiallerForm();
df->show();
app.exec();
}
I have compiled this application and running it as a server .
What i am expecting is that keyPressEvent slot be called whenever the key is pressed in the key pad. Instead , I get only the event:KeyPress function being called. And also the characters that i press in keypad are not displayed in the QLineEdit.
I can see that the kbd plugin part of the code is able to read the device and send it out. But the application is not able to get the QKeyEvent and subsequently the QLineEdit is also not updated.
What am i missing here. Could any one throw some light on how the key pad handling has to be done.
I have implemented a QT Key board plugin similar to the one given in Qt documentation
void QWSInputKbPrivate::readKeycode()
{
KEY_EVENT key[MAX_EVENTS_TO_READ];
int digit;
int events,current=0;
KEYPAD_KEYS keypad_key;
int pressed;
int keycode, unicode;
events = QT_READ(m_fd, reinterpret_cast<char *>(&key), MAX_EVENTS_TO_READ*sizeof(KEY_EVENT)) / sizeof(KEY_EVENT) ;
while (events!=current) {
keypad_key=digitToKeyArr[ key[current].column][key[current].row ];
pressed=key[current].key_press_time;
keycode = keysToQTArr[keypad_key].keycode;
unicode = keysToQTArr[keypad_key].unicode;
printf("readKeycode ---> key: %d press=%d, keycode=%d, unicode=%x %c\n", keypad_key, pressed, keycode, unicode, unicode);
m_handler->processKeyEvent(unicode, keycode, Qt::NoModifier, false, false);
current ++ ;
}
}
I am able to compile the key board plugin. I am able to set the QWS_KEYBOARD variable to this kbd plugin name. When starting an Qt application as server/client, the above printf function gets executed. So i understand that the character input hardware device is opened successfully and it is read correctly.
In the application, I have a single class deriving from QWidget. I create a instance of this class in the main program and show() it. This DiallerForm contains a single QLineEdit widget to get user input from key pad.
class DiallerForm : public QWidget
{
Q_OBJECT
public:
DiallerForm();
private slots:
void keyPressEvent(QKeyEvent *event);
bool event(QEvent *event);
private:
Ui::DiallerForm ui;
};
void DiallerForm::keyPressEvent(QKeyEvent *event) {
printf("DiallerForm::keyPressEvent \n");
}
bool DiallerForm::event(QEvent *event) {
switch(event->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease:
printf("DiallerForm::event - key press \n");
break;
default:
break;
}
return QWidget::event(event);
}
The main() code is something like this
int main(int argc, char **argv)
{
QApplication app(argc,argv);
DiallerForm *df = new DiallerForm();
df->show();
app.exec();
}
I have compiled this application and running it as a server .
What i am expecting is that keyPressEvent slot be called whenever the key is pressed in the key pad. Instead , I get only the event:KeyPress function being called. And also the characters that i press in keypad are not displayed in the QLineEdit.
I can see that the kbd plugin part of the code is able to read the device and send it out. But the application is not able to get the QKeyEvent and subsequently the QLineEdit is also not updated.
What am i missing here. Could any one throw some light on how the key pad handling has to be done.