Namespaces
Variants
Actions

Listening activation changes in Qt

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia E7, Nokia N8, Nokia N900

Compatibility
Platform(s): Symbian
Maemo

Article
Keywords: QEvent, QEvent::ActivationChange
Created: tepaa (12 Jan 2011)
Last edited: hamishwillee (11 Oct 2012)


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.

#include <QObject>
#include <QKeyEvent>
 
class MyEventFilter : public QObject
{
Q_OBJECT
public:
MyEventFilter(QObject *parent = 0);
~MyEventFilter();
protected:
bool eventFilter(QObject *obj, QEvent *event);
signals:
void activationChangeFiltered();
};


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.


See also

This page was last modified on 11 October 2012, at 04:17.
191 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved