Results 1 to 8 of 8

Thread: Some queries on the architecture of Qt character handling

  1. #1

    Default Some queries on the architecture of Qt character handling

    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:iallerForm 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Some queries on the architecture of Qt character handling

    Apparently your line edit doesn't have focus so it is the form that gets the event and since it can't accept focus, the event is ignored by QWidget::event(). The easiest solution is to make the line edit the focus proxy for the form. Alternatvely just set focus on the line edit.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3

    Default Re: Some queries on the architecture of Qt character handling

    I set the focus proxy for the line edit in the constructor of the form. Still it appears that line edit is not able to receive the QKeyEvent. I guess there is something far more monstrous is happening. Just not able to figure out what is happening.

    DiallerForm:iallerForm()
    {
    ui.setupUi(this);
    setWindowFlags(Qt::CustomizeWindowHint);

    setFocusProxy(ui.dialTextEdit);
    }


    Can i expect the QKeyEvent to get delivered to the containing form ?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Some queries on the architecture of Qt character handling

    Quote Originally Posted by balasaravanan View Post
    Can i expect the QKeyEvent to get delivered to the containing form ?
    If it doesn't itself accept focus then no. You can make it accept focus (change the focus policy) and keyPressEvent() will probably be getting called.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: Some queries on the architecture of Qt character handling

    I have tried setting the focus policy for the form .
    I tried setting the focus proxy to line edit.
    I also tried gradKeyboard for the form.

    None of the options display the keyed in characters in the line edit area. The QKeyEvent is not getting delivered for some reason i am not able to comprehend.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Some queries on the architecture of Qt character handling

    So far we are talking about receiving key events at all, not about displaying them in the line edit. If you want to display them in the line edit without additional coding then the line edit needs to have focus and not the form widget. It seems your line edit doesn't have focus or else you wouldn't be receiving any key related events in the form.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7

    Default Re: Some queries on the architecture of Qt character handling

    Hi wysota,

    Thanks for your replies. I really appreciate your help.

    Please find the attached tar ball for the source code. It contains a simple form with a line edit and two buttons.

    When i compile this code for x86, and run the program, i can see the keyboard input in the line edit. ie after i click on the line edit, the line edit comes to focus and gets all the keyboard inputs.

    When i compile the same code for the embedded board and run the program after setting QWS_KEYBOARD and starting the program as server, i do not get the key board input in the line edit. But i can see that the key board driver is sending the correct key events. Also the cursor blink is seen the line edit (ie the line edit has focus) .

    I am not sure if i need to have a separate program to run as server and start this program as a client in the embedded environment.

    Does it have to do anything with the driver program and how it is programmed. The crux of the driver code is as follows.

    Qt Code:
    1. void QWSInputKbPrivate::readKeycode()
    2. {
    3.  
    4. KEY_EVENT key[MAX_EVENTS_TO_READ];
    5. int digit;
    6. int events,current=0;
    7. KEYPAD_KEYS keypad_key;
    8. int pressed;
    9. int keycode, unicode;
    10.  
    11. events = QT_READ(m_fd, reinterpret_cast<char *>(&key), MAX_EVENTS_TO_READ*sizeof(KEY_EVENT)) / sizeof(KEY_EVENT) ;
    12.  
    13. while (events!=current) {
    14.  
    15. keypad_key=digitToKeyArr[ key[current].column][key[current].row ];
    16. pressed=key[current].key_press_time;
    17. keycode = keysToQTArr[keypad_key].keycode;
    18. unicode = keysToQTArr[keypad_key].unicode;
    19.  
    20. printf("readKeycode ---> key: %d press=%d, keycode=%d, unicode=%x %c\n", keypad_key, pressed, keycode, unicode, unicode);
    21.  
    22. m_handler->processKeyEvent(unicode, keycode, Qt::NoModifier, false, false);
    23. current ++ ;
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    Thanks and regards,
    Bala
    Attached Files Attached Files
    Last edited by wysota; 11th November 2011 at 11:26. Reason: missing [code] tags

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Some queries on the architecture of Qt character handling

    In my opinion your line edit doesn't have focus if you are receiving event() calls on the form.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 9
    Last Post: 19th November 2009, 10:18
  2. Character by Character (Unicode?) File Reading
    By mclark in forum Qt Programming
    Replies: 4
    Last Post: 22nd April 2009, 16:28
  3. How to read QStringList character by character
    By iamjayanth in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 12:25
  4. Special Character Handling
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2008, 23:58
  5. SQL date queries
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 11:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.