Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Revision as of 01:17, 11 October 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implementing area monitoring in Qt

From Wiki
Jump to: navigation, search

This code snippet demonstrates how to implement area monitoring in Qt using the Location module of Qt Mobility. It is assumed here that you have set up Qt Mobility in your development environment and on your device. For more information, see CS001615 - Setting up Qt Mobility.

Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Platform(s): S60 5th Edition, Maemo 5
Created: tapla (25 May 2010)
Last edited: hamishwillee (11 Oct 2012)


Qt project file

Link the Location module into the project:

CONFIG += mobility
MOBILITY = location

Using the Location module requires the Location capability:

symbian: {


#include <qgeoareamonitor.h>
#include <qgeopositioninfo.h>
// QtMobility namespace
class MainWindow : public QMainWindow
public slots:
* Called when the current position is in range of the area.

void areaEntered(const QGeoPositionInfo &update);
* Called when the current position moves out of range of the area.

void areaExited(const QGeoPositionInfo &update);
* Initializes the area monitor.

void initAreaMonitor();


#include <qgeocoordinate.h>
void MainWindow::initAreaMonitor()
// Create the area monitor
QGeoAreaMonitor *monitor = QGeoAreaMonitor::createDefaultMonitor(this);
// Connect the area monitoring signals to the corresponding slots
connect(monitor, SIGNAL(areaEntered(QGeoPositionInfo)),
this, SLOT(areaEntered(QGeoPositionInfo)));
connect(monitor, SIGNAL(areaExited(QGeoPositionInfo)),
this, SLOT(areaExited(QGeoPositionInfo)));
qreal latitude = 60.169966;
qreal longitude = 24.952115;
QGeoCoordinate myLocation(latitude, longitude);
void MainWindow::areaEntered(const QGeoPositionInfo &update) {
printString("The area has been entered.");
void MainWindow::areaExited(const QGeoPositionInfo &update) {
printString("The area has been exited.");


A specific area is defined and monitored.

See also

This page was last modified on 11 October 2012, at 01:17.
27 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.