Listening activation changes in Qt
Article Metadata
Tested with
Compatibility
Maemo
Article
Contents |
Overview
This snippet shows how to listen application activation changes in Qt. Activation changes means when application moves into foreground or background.
When incoming call is coming in Symbian and Maemo is native phone application opened on top of your application. In this case you can listen your application activation changes and for example pause the game when incoming call occurs.
This snippet was used in the Nokia Developer example QuickHit
Qt Event filter class
The filter event filters QEvent::ActivationChange event that occurs when your application moves into foreground or background.
MyEventFilter::MyEventFilter(QObject *parent) :
QObject(parent)
{
}
MyEventFilter::~MyEventFilter()
{
}
bool MyEventFilter::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ActivationChange) {
// QEvent::ActivationChange
// The application has been made available to the user
emit activationChangeFiltered();
return false;
} else {
// standard event processing
return QObject::eventFilter(obj, event);
}
}
Using event filter
Creating and installing event filter
// Create filter
MyEventFilter* eventFilter = new MyEventFilter(this);
// Listen filter signal
QObject::connect(eventFilter,SIGNAL(activationChangeFiltered()),this,SLOT(activationChangeFiltered()));
// Install filter into QApplication
qApp->installEventFilter(eventFilter);
Define slot into your application code to listen signal. In this example the game engine is paused when event occurs
void MainWindow::activationChangeFiltered()
{
// for example
m_gameEngine->pauseGame();
}
Postconditions
Incoming call, application hiding into background pauses the game.


(no comments yet)