×
Namespaces

Variants
Actions
Revision as of 08:29, 13 June 2012 by hamishwillee (Talk | contribs)

Detecting focus lost & gained events in Qt for Symbian

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Symbian
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
Qt 4.6.2
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Article
Keywords: symbianEventFilter, focus
Created: User:Kbwiki (26 Apr 2014)
Last edited: hamishwillee (13 Jun 2012)

Overview

This article explains how to detect focus change events in Qt applications on Symbian.

Description

Qt applications need to reimplement QApplication::symbianEventFilter() in order to get notification of foreground application changes, ie. focus lost & gained events. This is needed because focusInEvent(), focusOutEvent(), or hideEvent() from the QWidget class are not called on the Symbian platform when the foreground application changes.

Solution

Define an application class that inherits QApplication and reimplement symbianEventFilter():

  #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
};
165 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×