It is actually a very big program, I try to post part of the code here
void Login::setFilter()
{
LockLbl->installEventFilter( this );
Key1->installEventFilter( this );
Key2->installEventFilter( this );
Key3->installEventFilter( this );
Key4->installEventFilter( this );
Key5->installEventFilter( this );
Key6->installEventFilter( this );
Key7->installEventFilter( this );
Key8->installEventFilter( this );
Key9->installEventFilter( this );
Key0->installEventFilter( this );
Hyphen->installEventFilter( this );
BackSpace->installEventFilter( this );
Exit->installEventFilter( this );
Reset->installEventFilter( this );
Enter->installEventFilter( this );
ShowMode->installEventFilter( this );
ShowOutlet->installEventFilter( this );
LoginEdt->installEventFilter( this );
PasswdEdt->installEventFilter( this );
this->installEventFilter( this );
}
void Login::setFilter()
{
LockLbl->installEventFilter( this );
Key1->installEventFilter( this );
Key2->installEventFilter( this );
Key3->installEventFilter( this );
Key4->installEventFilter( this );
Key5->installEventFilter( this );
Key6->installEventFilter( this );
Key7->installEventFilter( this );
Key8->installEventFilter( this );
Key9->installEventFilter( this );
Key0->installEventFilter( this );
Hyphen->installEventFilter( this );
BackSpace->installEventFilter( this );
Exit->installEventFilter( this );
Reset->installEventFilter( this );
Enter->installEventFilter( this );
ShowMode->installEventFilter( this );
ShowOutlet->installEventFilter( this );
LoginEdt->installEventFilter( this );
PasswdEdt->installEventFilter( this );
this->installEventFilter( this );
}
To copy to clipboard, switch view to plain text mode
{
#if (QT_VERSION >= 0x030300)
if ( event
->type
() == QEvent::LanguageChange ) {
return true;
}
#endif
Logger l;
if( event
->type
() == QEvent::MouseButtonPress ||
event
->type
() == QEvent::MouseButtonDblClick ) {
if( widgetIgnore )
return true;
else
{
if( strcmp( object->name(), "LockLbl" )==0 )
{
lockEmployee();
setActiveWindow();
Reset_clicked();
}
}
}
if( event
->type
() == QEvent::FocusIn && object
->isA
( "QLineEdit" ) ) {
l.debug( "Login", "eventFilter FocusIn", focus + (string)" : " + object->name() );
if( focus == 'L' && strcmp( object->name(), "PasswdEdt" )==0 )
{
LoginEdt->setFocus();
return true;
}
if( focus == 'P' && strcmp( object->name(), "LoginEdt" )==0 )
{
PasswdEdt->setFocus();
return true;
}
}
if (event
->type
() ==QEvent::KeyPress && object
->isA
( "QLineEdit" )) {
//ut.showMsg( this, "2", tr( "KeyPressed" ) );
// Do nothing if not pressing Enter in touch screen mode
cout<<"TETING LOGIN"<<endl;
if( Gstation.getInputMode() == 1 && ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return )
{
return false;
}
keyClassification( ke );
return true;
}
else if( event
->type
() ==QEvent::WindowActivate ) {
if ( serialon == "yes" && slogin == "yes" )
{
if ( !proc->isRunning() )
{
cout << "init Serial" << endl;
if ( !proc->start() )
{
// error handling
cerr << "~~~~~~~ `` ERROR `` ~~~~~~~~" << endl;
}
}
}
this->setEnabled(true);
}
else if( event
->type
() ==QEvent::WindowDeactivate ) {
if ( !this->isHoldScreen )
{
shutSerial();
}
}
return false;
}
bool Login::eventFilter( QObject* object, QEvent *event )
{
#if (QT_VERSION >= 0x030300)
if ( event->type() == QEvent::LanguageChange )
{
return true;
}
#endif
Logger l;
if( event->type() == QEvent::MouseButtonPress ||
event->type() == QEvent::MouseButtonDblClick )
{
if( widgetIgnore )
return true;
else
{
if( strcmp( object->name(), "LockLbl" )==0 )
{
QApplication::beep();
lockEmployee();
setActiveWindow();
Reset_clicked();
}
}
}
if( event->type() == QEvent::FocusIn && object->isA( "QLineEdit" ) )
{
l.debug( "Login", "eventFilter FocusIn", focus + (string)" : " + object->name() );
if( focus == 'L' && strcmp( object->name(), "PasswdEdt" )==0 )
{
LoginEdt->setFocus();
return true;
}
if( focus == 'P' && strcmp( object->name(), "LoginEdt" )==0 )
{
PasswdEdt->setFocus();
return true;
}
}
if (event->type() ==QEvent::KeyPress && object->isA( "QLineEdit" ))
{
QKeyEvent *ke = (QKeyEvent *) event;
//ut.showMsg( this, "2", tr( "KeyPressed" ) );
// Do nothing if not pressing Enter in touch screen mode
cout<<"TETING LOGIN"<<endl;
if( Gstation.getInputMode() == 1 && ke->key() != Qt::Key_Enter && ke->key() != Qt::Key_Return )
{
return false;
}
keyClassification( ke );
return true;
}
else if( event->type() ==QEvent::WindowActivate )
{
if ( serialon == "yes" && slogin == "yes" )
{
if ( !proc->isRunning() )
{
cout << "init Serial" << endl;
if ( !proc->start() )
{
// error handling
cerr << "~~~~~~~ `` ERROR `` ~~~~~~~~" << endl;
}
}
}
this->setEnabled(true);
}
else if( event->type() ==QEvent::WindowDeactivate )
{
if ( !this->isHoldScreen )
{
shutSerial();
}
}
return false;
}
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.
Bookmarks