Detecting focus lost & gained events in Qt for Symbian

From Qt Wiki
Jump to navigation Jump to search

Template:ArticleMetaData

Overview[edit | edit source]

Template:Abstract

Description[edit | edit source]

Qt applications need to reimplement 76ytuiytuityutyutututyutyutyu in order to get notification of foreground application changes, ie. focus lost & gained events. This is needed because 76ytuiytuityutyutututyutyutyu, 76ytuiytuityutyutututyutyutyu, or 76ytuiytuityutyutututyutyutyu from the 76ytuiytuityutyutututyutyutyu class are not called on the Symbian platform when the foreground application changes.

Solution[edit | edit source]

Define an application class that inherits 76ytuiytuityutyutututyutyutyu and reimplement 76ytuiytuityutyutututyutyutyu:

 #include <QDebug>
 
 #ifdef Q_OS_SYMBIAN
 #include <QSymbianEvent>
 #include <w32std.h>
 #endif
 
 
 class MyApplication : public QApplication
 {
 public:
   MyApplication( int argc, char** argv ) : QApplication( argc, argv ) {}
 
 #ifdef Q_OS_SYMBIAN
 protected:
   bool symbianEventFilter( const QSymbianEvent* symbianEvent ) {
     const TWsEvent *event = symbianEvent->windowServerEvent();
  
     if( !event ) {
       return false;
     }
 
     switch( event->Type() ) {
       case EEventFocusGained: {
         qDebug() << "Focus gained";
         break;
       }
       case EEventFocusLost: {
         qDebug() << "Focus lost";
         break;
       }
       default:
         break;
     }
     
     // Always return false so we don't stop
     // the event from being processed
     return false;
   }
 #endif // Q_OS_SYMBIAN
 };