×
Namespaces

Variants
Actions
(Difference between revisions)

Detecting focus lost & gained events in Qt for Symbian

From Nokia Developer Wiki
Jump to: navigation, search
Forum Nokia KB (Talk | contribs)
m (Protected "TSQ001585 - Detecting focus lost & gained events in Qt for Symbian" ([edit=sysop] (indefinite) [move=sysop] (indefinite)))
Forum Nokia KB (Talk | contribs)
Line 65: Line 65:
 
   };
 
   };
 
</code>
 
</code>
[[Category:Published]][[Category:Qt for Symbian]][[Category:Qt]][[Category:Technical Solution]][[Category:S60 3rd Edition, Feature Pack 1]]
+
[[Category:Qt for Symbian]][[Category:Qt]][[Category:Technical Solution]][[Category:S60 3rd Edition, Feature Pack 1]][[Category:S60 3rd Edition, Feature Pack 2]][[Category:S60 5th Edition]][[Category:UI]]
[[Category:S60 3rd Edition, Feature Pack 2]][[Category:S60 5th Edition]][[Category:UI]]
+

Revision as of 10:00, 26 April 2010


Template:KBTS

Article Metadata
Tested with
Devices(s): S60
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
S60 3rd Edition FP1
Article
Keywords: symbianEventFilter
Created: (26 Apr 2014)
Last edited: Forum Nokia KB (26 Apr 2010)

Description

In Qt for Symbian, detecting foreground application changes, ie. focus lost & gained events, requires reimplementing the QApplication::symbianEventFilter() function.

This is required 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
};
101 page views in the last 30 days.
×