Implementing area monitoring in Qt
hamishwillee
(Talk | contribs) m (Hamishwillee - Bot update - Fix ArticleMetaData and minor updates) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (2 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | [[Category:Qt]][[Category:Qt Mobility]] | + | [[Category:Qt]][[Category:Qt Mobility]][[Category:Code Snippet]][[Category:MeeGo Harmattan]][[Category:Symbian]][[Category:Location]] |
| − | + | {{Abstract|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]]. | |
| − | + | ||
{{ArticleMetaData <!-- v1.2 --> | {{ArticleMetaData <!-- v1.2 --> | ||
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | |sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) --> | ||
| Line 23: | Line 23: | ||
|creationdate= 20100525 | |creationdate= 20100525 | ||
|author= [[User:Tapla]] | |author= [[User:Tapla]] | ||
| − | |||
| − | |||
}} | }} | ||
| − | |||
| − | |||
| − | |||
| − | |||
==Qt project file== | ==Qt project file== | ||
| Line 35: | Line 29: | ||
Link the Location module into the project: | Link the Location module into the project: | ||
| − | <code cpp> | + | <code cpp-qt> |
CONFIG += mobility | CONFIG += mobility | ||
MOBILITY = location | MOBILITY = location | ||
| Line 42: | Line 36: | ||
Using the Location module requires the Location capability: | Using the Location module requires the Location capability: | ||
| − | <code cpp> | + | <code cpp-qt> |
symbian: { | symbian: { | ||
TARGET.CAPABILITY = Location | TARGET.CAPABILITY = Location | ||
| Line 50: | Line 44: | ||
==Header== | ==Header== | ||
| − | <code cpp> | + | <code cpp-qt> |
#include <qgeoareamonitor.h> | #include <qgeoareamonitor.h> | ||
#include <qgeopositioninfo.h> | #include <qgeopositioninfo.h> | ||
| Line 81: | Line 75: | ||
==Source== | ==Source== | ||
| − | <code cpp> | + | <code cpp-qt> |
#include <qgeocoordinate.h> | #include <qgeocoordinate.h> | ||
</code> | </code> | ||
| − | <code cpp> | + | <code cpp-qt> |
void MainWindow::initAreaMonitor() | void MainWindow::initAreaMonitor() | ||
{ | { | ||
| Line 120: | Line 114: | ||
* [[CS001615 - Setting up Qt Mobility]] | * [[CS001615 - Setting up Qt Mobility]] | ||
* http://doc.qt.nokia.com/qtmobility-1.0/location-overview.html | * http://doc.qt.nokia.com/qtmobility-1.0/location-overview.html | ||
| − | |||
| − | |||
Latest revision as of 04:17, 11 October 2012
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
Compatibility
Platform(s): S60 5th Edition, Maemo 5
Article
Created: tapla
(25 May 2010)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Qt project file
Link the Location module into the project:
CONFIG += mobility
MOBILITY = location
Using the Location module requires the Location capability:
symbian: {
TARGET.CAPABILITY = Location
}
Header
#include <qgeoareamonitor.h>
#include <qgeopositioninfo.h>
// QtMobility namespace
QTM_USE_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
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);
private:
/**
* Initializes the area monitor.
*/
void initAreaMonitor();
}
Source
#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);
monitor->setCenter(myLocation);
monitor->setRadius(100);
}
void MainWindow::areaEntered(const QGeoPositionInfo &update) {
printString("The area has been entered.");
}
void MainWindow::areaExited(const QGeoPositionInfo &update) {
printString("The area has been exited.");
}
Postconditions
A specific area is defined and monitored.

