×
Namespaces

Variants
Actions
(Difference between revisions)

Implementing area monitoring in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Addition to article of: Category:MeeGo Category:Symbian. (Add platform categories))
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix ArticleMetaData and minor updates)
Line 2: Line 2:
 
__NOTOC__
 
__NOTOC__
 
__NOEDITSECTION__
 
__NOEDITSECTION__
{{ArticleMetaData
+
{{ArticleMetaData <!-- v1.2 -->
|id=
+
|platform=S60 5th Edition, Maemo 5
+
|devices=Nokia 5800 XpressMusic
+
|category=Qt
+
|subcategory=Qt Mobility
+
|creationdate=May 24, 2010
+
|keywords=
+
 
+
 
|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]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= Nokia 5800 XpressMusic
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= S60 5th Edition, Maemo 5
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Tapla]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20100525
 +
|author= [[User:Tapla]]
 +
<!-- The following are not in current metadata -->
 +
|subcategory= Qt Mobility
 
}}
 
}}
  
 
==Overview==
 
==Overview==
  
{{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 [[Setting up Qt Mobility]].
+
{{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]].
  
 
==Qt project file==
 
==Qt project file==
Line 111: Line 118:
 
==See also==
 
==See also==
  
* [[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
  
[[Category:Code Examples]][[Category:Code Snippet]][[Category:MeeGo]] [[Category:Symbian]]
+
[[Category:Code Snippet]][[Category:Code Snippet]][[Category:MeeGo]] [[Category:Symbian]]

Revision as of 08:31, 8 March 2012


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

Overview

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.

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.

See also

60 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.

×