Results 1 to 4 of 4

Thread: QEvent problem

  1. #1
    Join Date
    Jun 2008
    Posts
    64
    Thanks
    7
    Qt products
    Qt3 Qt4

    Default QEvent problem

    Is there any possible reason that an ui will ignore keyboard event?
    The case is like this: I am having an ui form, and installed the eventFilter to the form. So if there's key pressed from keyboard, it should run the event filter code. It works well originally, however after some actions, e.g. opening new ui form etc. I found that the event can no longer be detected!

    How can I know if it is the form that missed the event signal, or there's actually no signal sent from the keyboard?

  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: QEvent problem

    Quote Originally Posted by batileon View Post
    Is there any possible reason that an ui will ignore keyboard event?
    No, I don't think so.

    The case is like this: I am having an ui form, and installed the eventFilter to the form. So if there's key pressed from keyboard, it should run the event filter code. It works well originally, however after some actions, e.g. opening new ui form etc. I found that the event can no longer be detected!
    Can we see the code?

    How can I know if it is the form that missed the event signal, or there's actually no signal sent from the keyboard?
    You can install an event filter on the application object. All events from within the application will be passing through it.
    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
    Jun 2008
    Posts
    64
    Thanks
    7
    Qt products
    Qt3 Qt4

    Default Re: QEvent problem

    It is actually a very big program, I try to post part of the code here

    Qt Code:
    1. void Login::setFilter()
    2. {
    3. LockLbl->installEventFilter( this );
    4.  
    5. Key1->installEventFilter( this );
    6. Key2->installEventFilter( this );
    7. Key3->installEventFilter( this );
    8. Key4->installEventFilter( this );
    9. Key5->installEventFilter( this );
    10. Key6->installEventFilter( this );
    11. Key7->installEventFilter( this );
    12. Key8->installEventFilter( this );
    13. Key9->installEventFilter( this );
    14. Key0->installEventFilter( this );
    15. Hyphen->installEventFilter( this );
    16. BackSpace->installEventFilter( this );
    17. Exit->installEventFilter( this );
    18. Reset->installEventFilter( this );
    19. Enter->installEventFilter( this );
    20.  
    21. ShowMode->installEventFilter( this );
    22. ShowOutlet->installEventFilter( this );
    23. LoginEdt->installEventFilter( this );
    24. PasswdEdt->installEventFilter( this );
    25. this->installEventFilter( this );
    26. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. bool Login::eventFilter( QObject* object, QEvent *event )
    2. {
    3. #if (QT_VERSION >= 0x030300)
    4. if ( event->type() == QEvent::LanguageChange )
    5. {
    6. return true;
    7. }
    8. #endif
    9. Logger l;
    10. if( event->type() == QEvent::MouseButtonPress ||
    11. event->type() == QEvent::MouseButtonDblClick )
    12. {
    13. if( widgetIgnore )
    14. return true;
    15. else
    16. {
    17. if( strcmp( object->name(), "LockLbl" )==0 )
    18. {
    19. QApplication::beep();
    20. lockEmployee();
    21. setActiveWindow();
    22. Reset_clicked();
    23. }
    24. }
    25. }
    26. if( event->type() == QEvent::FocusIn && object->isA( "QLineEdit" ) )
    27. {
    28. l.debug( "Login", "eventFilter FocusIn", focus + (string)" : " + object->name() );
    29. if( focus == 'L' && strcmp( object->name(), "PasswdEdt" )==0 )
    30. {
    31. LoginEdt->setFocus();
    32. return true;
    33. }
    34. if( focus == 'P' && strcmp( object->name(), "LoginEdt" )==0 )
    35. {
    36. PasswdEdt->setFocus();
    37. return true;
    38. }
    39. }
    40. if (event->type() ==QEvent::KeyPress && object->isA( "QLineEdit" ))
    41. {
    42. QKeyEvent *ke = (QKeyEvent *) event;
    43. //ut.showMsg( this, "2", tr( "KeyPressed" ) );
    44. // Do nothing if not pressing Enter in touch screen mode
    45. cout<<"TETING LOGIN"<<endl;
    46. if( Gstation.getInputMode() == 1 && ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return )
    47. {
    48. return false;
    49. }
    50.  
    51. keyClassification( ke );
    52. return true;
    53. }
    54. else if( event->type() ==QEvent::WindowActivate )
    55. {
    56. if ( serialon == "yes" && slogin == "yes" )
    57. {
    58. if ( !proc->isRunning() )
    59. {
    60. cout << "init Serial" << endl;
    61. if ( !proc->start() )
    62. {
    63. // error handling
    64. cerr << "~~~~~~~ `` ERROR `` ~~~~~~~~" << endl;
    65. }
    66. }
    67. }
    68. this->setEnabled(true);
    69. }
    70. else if( event->type() ==QEvent::WindowDeactivate )
    71. {
    72. if ( !this->isHoldScreen )
    73. {
    74. shutSerial();
    75. }
    76. }
    77. return false;
    78. }
    To copy to clipboard, switch view to plain text mode 

    So, there's a line of cout in the event filter loop for QEvent::KeyPress, and the object I am filtering is really a QLineEdit. However, the cout never appear when the case I mentioned occurs, i.e. It works well at the beginning, and fail after calling some more ui.

  4. #4
    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: QEvent problem

    Hmmm.... what are those event filters suppose to do? Can't use use signals and slots instead? Installing event filters on 20 objects might not be the best design decision, I'm almost sure there is a simpler way to do what you are trying to do.
    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. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  3. QObject / QEvent compilation problem after reinstallation?
    By hickscorp in forum Installation and Deployment
    Replies: 12
    Last Post: 11th May 2007, 00:23
  4. qevent problem
    By amulya in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2006, 12:51
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.