Results 1 to 13 of 13

Thread: Qt Embedded Linux - QWSKeyboardHandler

  1. #1
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Qt Embedded Linux - QWSKeyboardHandler

    Hi!

    We're using a biometric sensor as input device for an embedded project.

    I've created a QWSKeyboardHandler derived class which sends some key press events to the QWSServer instance. It uses the QWSKeyboardHandler::processKeyEvent method to send all key press events.

    Qt Code:
    1. pkFingerPrintManager::pkFingerPrintManager()
    2. {
    3. QWSServer::setKeyboardHandler(this);
    4. }
    5.  
    6. // ... CUT ...
    7.  
    8. void pkFingerPrintManager::notifyInputEvent(int dx, int dy, int state)
    9. {
    10. if (this->isNavigateRunning())
    11. {
    12. m_dx += dx;
    13. m_dy += dy;
    14.  
    15. if (m_dx >= PK_FPM_KEY_THRESHOLD)
    16. {
    17. this->processKeyEvent(QEvent::KeyPress, Qt::Key_Right, 0, true, false);
    18. m_dx = 0;
    19. }
    20.  
    21. if (m_dx <= -PK_FPM_KEY_THRESHOLD)
    22. {
    23. this->processKeyEvent(QEvent::KeyPress, Qt::Key_Left, 0, true, false);
    24. m_dx = 0;
    25. }
    26.  
    27. if (m_dy >= PK_FPM_KEY_THRESHOLD)
    28. {
    29. this->processKeyEvent(QEvent::KeyPress, Qt::Key_Down, 0, true, false);
    30. m_dy = 0;
    31. }
    32.  
    33. if (m_dy <= -PK_FPM_KEY_THRESHOLD)
    34. {
    35. this->processKeyEvent(QEvent::KeyPress, Qt::Key_Up, 0, true, false);
    36. m_dy = 0;
    37. }
    38.  
    39. if (dx == 0)
    40. m_dx = 0;
    41.  
    42. if (dy == 0)
    43. m_dy = 0;
    44. }
    45. }
    To copy to clipboard, switch view to plain text mode 

    On my test machine (Linux x86) everything works.

    Now we are testing it on the final ARM-based architecture but no key event is sent (or received). The process flow enters in one of the four "if" statements but the test widget doesn't receive any events.

    This is the test widget "keyPressEvent" filter body:

    Qt Code:
    1. void TestWidget::keyPressEvent(QKeyEvent* event)
    2. {
    3. if (event->key() == Qt::Key_Left)
    4. {
    5. // ...
    6.  
    7. event->accept();
    8.  
    9. return;
    10. }
    11.  
    12. if (event->key() == Qt::Key_Right)
    13. {
    14. // ...
    15.  
    16. event->accept();
    17.  
    18. return;
    19. }
    20.  
    21. // ...
    22.  
    23. event->ignore();
    24. }
    To copy to clipboard, switch view to plain text mode 

    Could you help me to find the problem, please?

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

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    Maybe the problem is not in the keyboard handler? Are you sure your widget has keyboard focus? You could try applying an event filter on the application object and see if the events are delivered to the application at all.
    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
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    I'm using "grabKeyboard" method to connect all key events to its parent widget. On my x86 machine it works.

  4. #4
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    I've added these lines to my QApplication (server) instance:

    Qt Code:
    1. class MyKeyboardFilter : public KeyboardFilter
    2. {
    3. public:
    4. bool filter(int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat)
    5. {
    6. qDebug() << unicode << keycode << isPress;
    7.  
    8. return false;
    9. }
    10. }
    11.  
    12. // ... CUT ...
    13.  
    14. qwsServer->addKeyboardFilter(new MyKeyboardFilter());
    15. qwsServer->sendKeyEvent(QEvent::KeyPress, Qt::Key_Up, 0, true, false);
    To copy to clipboard, switch view to plain text mode 

    but the "filter" method is never called

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

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    Did you do what I suggested?
    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.


  6. #6
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    Yes, as I've already said, I've created a keyoboard event filter in the QWSServer instance but it's never invoked...

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

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    That's not what I told you to do... And I see you didn't even read the docs of a method you used:
    Note that the filter is not invoked for keys generated by virtual keyboard drivers (i.e., events sent using the sendKeyEvent() function).
    I told you to install an event filter on the application object and not to set a keyboard filter on the server object.
    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.


  8. #8
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    You're right, I'm sorry.

    Well, I've added an event filter to my QApplication instance:

    Qt Code:
    1. class KeyPressEater : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. KeyPressEater() : QObject(0) {};
    7. virtual ~KeyPressEater() {};
    8.  
    9. protected:
    10. bool eventFilter(QObject *obj, QEvent *event);
    11. };
    12.  
    13. bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
    14. {
    15. qDebug() << event->type();
    16.  
    17. if (event->type() == QEvent::KeyPress) {
    18.  
    19. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    20. qDebug("Key press %d", keyEvent->key());
    21. return false;
    22.  
    23. } else {
    24.  
    25. // standard event processing
    26. return QObject::eventFilter(obj, event);
    27. }
    28. }
    29.  
    30. // In QApplication code:
    31. this->installEventFilter(new KeyPressEater());
    To copy to clipboard, switch view to plain text mode 

    No key press event is received by my QApplication object.

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

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    On both x86 and ARM?
    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.


  10. #10
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    No, on the x86 platform all key events are correctly received and printed by the qDebug statement.

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

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    The first argument of processKeyEvent() is wrong. It should contain the unicode value of the key, not QEvent::KeyPress. Also make sure if the constructor of your subclass is called at all.
    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.


  12. #12
    Join Date
    Mar 2009
    Posts
    72
    Thanks
    7
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    Quote Originally Posted by wysota View Post
    The first argument of processKeyEvent() is wrong. It should contain the unicode value of the key, not QEvent::KeyPress...
    I'm a bit confused Why I need to specify both unicode and key code?

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

    Default Re: Qt Embedded Linux - QWSKeyboardHandler

    Don't ask me. I'm just looking at the API.
    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. QT 4.5 Embedded Linux Demo Web Browser does not work
    By saltuka in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2010, 04:11
  2. Replies: 1
    Last Post: 3rd December 2008, 22:15
  3. Replies: 0
    Last Post: 22nd June 2008, 15:18
  4. Qt Development on Win for Embedded Linux
    By pwb in forum Installation and Deployment
    Replies: 2
    Last Post: 21st April 2008, 19:30

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.