Get continuous location updates using Qt Mobility API
Article Metadata
Tested with
Devices(s): Nokia N97 Mini
Compatibility
Platform(s): S60 5th Edition
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


Srinivas.p.v - geopositioninfo::positionupdate and geopositioninfo::direction does not work
the positionupdate() does not work in QT Creator SDK but i have not tried it on the phone..can anyone plz suggest me the code for getting the updates of position and the direction on the QT Creator SDK.Can anyone tell me the reason for why the updates are not working even after using the setInterval() function.srinivas.p.v 17:04, 25 November 2011 (EET)
Hamishwillee - Try the forums
Obvious question, but on the Simulator, you are simulating position information right? You won't get any updates if you're not! The wiki is not the right place to get "technical support" - its where you comment on specific issues with articles. If you need help, please raise the query on the forums.
Regards
Hamishhamishwillee 07:36, 1 December 2011 (EET)