×
Namespaces

Variants
Actions

Listening activation changes in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia E7, Nokia N8, Nokia N900
Compatibility
Platform(s): Symbian
Maemo
Symbian
Article
Keywords: QEvent, QEvent::ActivationChange
Created: tepaa (12 Jan 2011)
Last edited: kiran10182 (31 Oct 2013)


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 31 October 2013, at 22:31.
84 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.

×