Namespaces

Variants
Actions

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.

Get continuous location updates using Qt Mobility API

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N97 Mini
Compatibility
Platform(s): S60 5th Edition
Symbian
Article
Keywords: QGeoPositionInfoSource, QGeoPositionInfo
Created: skumar_rao (15 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

How to get continuous location updates using Qt Mobility API

Project configuration file (.Pro file)

  • Add the Qt Mobility project configuration option in the .Pro file as shown below
CONFIG += mobility
MOBILITY += location

Header File

#include <QObject>
#include <QGeoPositionInfoSource>
using namespace QtMobility;
 
class LocationWatcher : public QObject
{
Q_OBJECT
 
public:
LocationWatcher(QObject *parent = 0);
void enable();
void disable();
 
private slots:
void positionUpdated(const QGeoPositionInfo &info);
 
private:
QGeoPositionInfoSource *source;
};

Source File

#include <QDebug>
 
#include "locationwatcher.h"
 
LocationWatcher::LocationWatcher(QObject *parent)
: QObject(parent)
{
source = QGeoPositionInfoSource::createDefaultSource(this);
if (source) {
source->setUpdateInterval(1000); // time in milliseconds
source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);
}
}
 
void LocationWatcher::enable()
{
if (source) {
connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
source->startUpdates();
}
}
 
void LocationWatcher::disable()
{
if (source) {
source->stopUpdates();
disconnect(source, SIGNAL(positionUpdated(QGeoPositionInfo)),
this, SLOT(positionUpdated(QGeoPositionInfo)));
}
}
 
void LocationWatcher::positionUpdated(const QGeoPositionInfo &info)
{
if (info.isValid()) {
qDebug() << info;
}
}

Classes

  • QGeoPositionInfoSource
  • QGeoPositionInfo

Reference links

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

×