Since: 1.0

#include <QtLocationSubset/QNmeaPositionInfoSource>

The QNmeaPositionInfoSource class provides positional information using a NMEA data source.

NMEA is a commonly used protocol for the specification of one's global position at a certain point in time. The QNmeaPositionInfoSource class reads NMEA data and uses it to provide positional data in the form of QGeoPositionInfo objects.

A QNmeaPositionInfoSource instance operates in either {RealTimeMode} or {SimulationMode}. These modes allow NMEA data to be read from either a live source of positional data, or replayed for simulation purposes from previously recorded NMEA data.

The source of NMEA data is set with setDevice().

Use startUpdates() to start receiving regular position updates and stopUpdates() to stop these updates. If you only require updates occasionally, you can call requestUpdate() to request a single update.

In both cases the position information is received via the positionUpdated() signal and the last known position can be accessed with lastKnownPosition().




Public Types Index

enum UpdateMode

RealTimeMode = 1, SimulationMode

enum PositioningMethod

SatellitePositioningMethods = 0x000000ff, NonSatellitePositioningMethods = 0xffffff00, AllPositioningMethods = 0xffffffff

Properties Index

Only has inherited properties

intminimumUpdateInterval [read-only]Inherited

Public Functions Index

QNmeaPositionInfoSource (UpdateMode updateMode, QObject *parent=0)
~QNmeaPositionInfoSource ()
QIODevice *device () const
virtual QGeoPositionInfolastKnownPosition (bool fromSatellitePositioningMethodsOnly=false) const
virtual intminimumUpdateInterval () const
voidsetDevice (QIODevice *source)
virtual voidsetUpdateInterval (int msec)
virtual PositioningMethodssupportedPositioningMethods () const
UpdateModeupdateMode () const
PositioningMethodspreferredPositioningMethods () const Inherited
QGeoPositionInfoSource (QObject *parent)Inherited
virtual voidsetPreferredPositioningMethods (PositioningMethods methods)Inherited
intupdateInterval () const Inherited

Static Public Functions Index

Only has inherited static public functions

QStringListavailableSources ()Inherited
QGeoPositionInfoSource *createDefaultSource (QObject *parent)Inherited
QGeoPositionInfoSource *createSource (const QString &sourceName, QObject *parent)Inherited

Protected Functions Index

virtual boolparsePosInfoFromNmeaData (const char *data, int size, QGeoPositionInfo *posInfo, bool *hasFix)

Public Slots Index

voidrequestUpdate (int timeout=0)
voidstartUpdates ()
voidstopUpdates ()

Signals Index

Only has inherited signals

voidpositionUpdated (const QGeoPositionInfo &update)Inherited
voidupdateTimeout ()Inherited

Public Types


Defines the available update modes.

RealTimeMode Positional data is read and distributed from the data source as it becomes available. Use this mode if you are using a live source of positional data (for example, a GPS hardware device). SimulationMode The data and time information in the NMEA source data is used to provide positional updates at the rate at which the data was originally recorded. Use this mode if the data source contains previously recorded NMEA data and you want to replay the data for simulation purposes.

RealTimeMode = 1

PositioningMethod Inherited

Defines the types of positioning methods.

SatellitePositioningMethods Satellite-based positioning methods such as GPS. NonSatellitePositioningMethods Other positioning methods. AllPositioningMethods A flag that matches all positioning methods.

SatellitePositioningMethods = 0x000000ff
NonSatellitePositioningMethods = 0xffffff00
AllPositioningMethods = 0xffffffff


(Only has inherited properties)

int minimumUpdateIntervalInherited[read-only]

This property holds the minimum time (in milliseconds) required to retrieve a position update.

This is the minimum value accepted by setUpdateInterval() and requestUpdate().

int updateIntervalInherited

This property holds the requested interval in milliseconds between each update.

If the update interval is not set (or is set to 0) the source will provide updates as often as necessary.

If the update interval is set, the source will provide updates at an interval as close to the requested interval as possible. If the requested interval is less than the minimumUpdateInterval(), the minimum interval is used instead.

Changes to the update interval will happen as soon as is practical, however the time the change takes may vary between implementations. Whether or not the elapsed time from the previous interval is counted as part of the new interval is also implementation dependent.

The default value for this property is 0.

Note: Subclass implementations must call the base implementation of setUpdateInterval() so that updateInterval() returns the correct value.

Public Functions

QNmeaPositionInfoSource (

Constructs a QNmeaPositionInfoSource instance with the given parent and updateMode.

~QNmeaPositionInfoSource ()


QIODevice * device ()

Returns the NMEA data source.

virtualQGeoPositionInfo lastKnownPosition (
  • boolfromSatellitePositioningMethodsOnly)

virtual int minimumUpdateInterval ()

void setDevice (

Sets the NMEA data source to device.

If the device is not open, it will be opened in QIODevice::ReadOnly mode.

The source device can only be set once and must be set before calling startUpdates() or requestUpdate().

{Note:} The device must emit QIODevice::readyRead() for the source to be notified when data is available for reading. QNmeaPositionInfoSource does not assume the ownership of the device, and hence does not deallocate it upon destruction.

virtual void setUpdateInterval (
  • intmsec)

virtual PositioningMethods supportedPositioningMethods ()

UpdateMode updateMode ()

Returns the update mode.

PositioningMethods preferredPositioningMethods ()Inherited

Returns the positioning methods set by setPreferredPositioningMethods().

QGeoPositionInfoSource (Inherited

Creates a position source with the specified parent.

virtual void setPreferredPositioningMethods (
  • PositioningMethodsmethods)

Sets the preferred positioning methods for this source to methods.

If methods includes a method that is not supported by the source, the unsupported method will be ignored.

If methods does not include any methods supported by the source, the preferred methods will be set to the set of methods which the source supports.

{Note:} When reimplementing this method, subclasses must call the base method implementation to ensure preferredPositioningMethods() returns the correct value.

int updateInterval ()Inherited

Static Public Functions

(Only has inherited static public functions)

QStringList availableSources ()Inherited

Returns a list of available source plugins.

Note that this list does not include the default platform backend, if one is available.

QGeoPositionInfoSource * createDefaultSource (Inherited

Creates and returns a position source with the given parent that reads from the system's default sources of location data, or the plugin with the highest available priority.

Returns 0 if the system has no default position source and no valid plugins could be found.

QGeoPositionInfoSource * createSource (Inherited

Creates and returns a position source with the given parent, by loading the plugin named sourceName.

Returns 0 if the plugin cannot be found.

Protected Functions

virtual bool parsePosInfoFromNmeaData (

Parses an NMEA sentence string into a QGeoPositionInfo.

The default implementation will parse standard NMEA sentences. This method should be reimplemented in a subclass whenever the need to deal with non-standard NMEA sentences arises.

The parser reads size bytes from data and uses that information to setup posInfo and hasFix. If hasFix is set to false then posInfo may contain only the time or the date and the time.

Returns true if the sentence was succsesfully parsed, otherwise returns false and should not modify posInfo or hasFix.

Public Slots

void requestUpdate (
  • inttimeout)

void startUpdates ()

void stopUpdates ()


(Only has inherited signals)

void positionUpdated (Inherited

If startUpdates() or requestUpdate() is called, this signal is emitted when an update becomes available.

The update value holds the value of the new update.

void updateTimeout ()Inherited

If requestUpdate() was called, this signal will be emitted if the current position could not be retrieved within the specified timeout.

If startUpdates() has been called, this signal will be emitted if this QGeoPositionInfoSource subclass determines that it will not be able to provide further regular updates. This signal will not be emitted again until after the regular updates resume.

Last modified: 2014-03-13

comments powered by Disqus