QGeoPositionInfoSource Class | Qt Positioning 5.6

Qt 5.6 | Qt Positioning | C++ Classes | QGeoPositionInfoSource

Qt 5.6.2 Reference Documentation

# QGeoPositionInfoSource Class

The QGeoPositionInfoSource class is an abstract base class for the distribution of positional updates. More...

Header: | #include <QGeoPositionInfoSource>
qmake: | QT += positioning
Since: | Qt 5.2
Inherits: | QObject
Inherited By: | QNmeaPositionInfoSource

- List of all members, including inherited members

## Public Types

enum | Error { AccessError, ClosedError, NoError, UnknownSourceError }
enum | PositioningMethod { NoPositioningMethods, SatellitePositioningMethods, NonSatellitePositioningMethods, AllPositioningMethods }
flags | PositioningMethods

## Properties

- minimumUpdateInterval : const int
- sourceName : const QString
- updateInterval : int

- 1 property inherited from QObject

## Public Functions

| QGeoPositionInfoSource(QObject *parent)
virtual | ~QGeoPositionInfoSource()
virtual Error | error() const = 0
virtual QGeoPositionInfo | lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const = 0
virtual int | minimumUpdateInterval() const = 0
PositioningMethods | preferredPositioningMethods() const
virtual void | setPreferredPositioningMethods(PositioningMethods methods)
virtual void | setUpdateInterval(int msec)
QString | sourceName() const
virtual PositioningMethods | supportedPositioningMethods() const = 0
int | updateInterval() const

- 31 public functions inherited from QObject

## Public Slots

virtual void | requestUpdate(int timeout = 0) = 0
virtual void | startUpdates() = 0
virtual void | stopUpdates() = 0

- 1 public slot inherited from QObject

## Signals

void | error(QGeoPositionInfoSource::Error positioningError)
void | positionUpdated(const QGeoPositionInfo &update)
void | updateTimeout()

- 2 signals inherited from QObject

## Static Public Members

QStringList | availableSources()
QGeoPositionInfoSource * | createDefaultSource(QObject *parent)
QGeoPositionInfoSource * | createSource(const QString &sourceName, QObject *parent)

- 10 static public members inherited from QObject

### Additional Inherited Members

- 1 public variable inherited from QObject
- 9 protected functions inherited from QObject
- 2 protected variables inherited from QObject

## Detailed Description

The QGeoPositionInfoSource class is an abstract base class for the distribution of positional updates.

The static function QGeoPositionInfoSource::createDefaultSource() creates a default position source that is appropriate for the platform, if one is available. Otherwise, QGeoPositionInfoSource will check for available plugins that implement the QGeoPositionInfoSourceFactory interface.

Users of a QGeoPositionInfoSource subclass can request the current position using requestUpdate(), or start and stop regular position updates using startUpdates() and stopUpdates(). When an update is available, positionUpdated() is emitted. The last known position can be accessed with lastKnownPosition().

If regular position updates are required, setUpdateInterval() can be used to specify how often these updates should be emitted. If no interval is specified, updates are simply provided whenever they are available. For example:

      // Emit updates every 10 seconds if available
      QGeoPositionInfoSource *source = QGeoPositionInfoSource::createDefaultSource(0);
      if (source)
          source->setUpdateInterval(10000);

To remove an update interval that was previously set, call setUpdateInterval() with a value of 0.

Note that the position source may have a minimum value requirement for update intervals, as returned by minimumUpdateInterval().

Warning: On Windows CE it is not possible to detect if a device is GPS enabled. The default position source on a Windows CE device without GPS support will never provide any position data.

## Member Type Documentation

### enum QGeoPositionInfoSource::Error

The Error enumeration represents the errors which can occur.

Constant | Value | Description
--- | --- | ---
`QGeoPositionInfoSource::AccessError` | `0` | The connection setup to the remote positioning backend failed because the application lacked the required privileges.
`QGeoPositionInfoSource::ClosedError` | `1` | The remote positioning backend closed the connection, which happens for example in case the user is switching location services to off. As soon as the location service is re-enabled regular updates will resume.
`QGeoPositionInfoSource::NoError` | `3` | No error has occurred.
`QGeoPositionInfoSource::UnknownSourceError` | `2` | An unidentified error occurred.

### enum QGeoPositionInfoSource::PositioningMethod
flags QGeoPositionInfoSource::PositioningMethods

Defines the types of positioning methods.

Constant | Value | Description
--- | --- | ---
`QGeoPositionInfoSource::NoPositioningMethods` | `0x00000000` | None of the positioning methods.
`QGeoPositionInfoSource::SatellitePositioningMethods` | `0x000000ff` | Satellite-based positioning methods such as GPS or GLONASS.
`QGeoPositionInfoSource::NonSatellitePositioningMethods` | `0xffffff00` | Other positioning methods such as 3GPP cell identifier or WiFi based positioning.
`QGeoPositionInfoSource::AllPositioningMethods` | `0xffffffff` | Satellite-based positioning methods as soon as available. Otherwise non-satellite based methods.

The PositioningMethods type is a typedef for QFlags<PositioningMethod>. It stores an OR combination of PositioningMethod values.

## Property Documentation

### minimumUpdateInterval : const int

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

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

Access functions:

virtual int | minimumUpdateInterval() const = 0

### sourceName : const QString

This property holds this property holds the unique name of the position source implementation in use.

This is the same name that can be passed to createSource() in order to create a new instance of a particular position source implementation.

Access functions:

QString | sourceName() const

### updateInterval : int

This property holds 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.

Access functions:

int | updateInterval() const
virtual void | setUpdateInterval(int msec)

## Member Function Documentation

### QGeoPositionInfoSource::QGeoPositionInfoSource(QObject *parent)

Creates a position source with the specified parent.

### `[virtual]` QGeoPositionInfoSource::~QGeoPositionInfoSource()

Destroys the position source.

### `[static]` QStringList QGeoPositionInfoSource::availableSources()

Returns a list of available source plugins. This includes any default backend plugin for the current platform.

### `[static]` QGeoPositionInfoSource *QGeoPositionInfoSource::createDefaultSource(QObject *parent)

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, no valid plugins could be found or the user does not have the permission to access the current position.

### `[static]` QGeoPositionInfoSource *QGeoPositionInfoSource::createSource(const QString &sourceName, QObject *parent)

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

Returns 0 if the plugin cannot be found.

### `[pure virtual]` Error QGeoPositionInfoSource::error() const

Returns the type of error that last occurred.

### `[signal]` void QGeoPositionInfoSource::error(QGeoPositionInfoSource::Error positioningError)

This signal is emitted after an error occurred. The positioningError parameter describes the type of error that occurred.

This signal is not emitted when an updateTimeout() has occurred.

Note: Signal error is overloaded in this class. To connect to this one using the function pointer syntax, you must specify the signal type in a static cast, as shown in this example:

      connect(geoPositionInfoSource, static_cast<void(QGeoPositionInfoSource::*)(QGeoPositionInfoSource::Error)>(&QGeoPositionInfoSource::error),
          [=](QGeoPositionInfoSource::Error positioningError){ /* ... */ });

### `[pure virtual]` QGeoPositionInfo QGeoPositionInfoSource::lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const

Returns an update containing the last known position, or a null update if none is available.

If fromSatellitePositioningMethodsOnly is true, this returns the last known position received from a satellite positioning method; if none is available, a null update is returned.

### `[signal]` void QGeoPositionInfoSource::positionUpdated(const QGeoPositionInfo &update)

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.

### PositioningMethods QGeoPositionInfoSource::preferredPositioningMethods() const

Returns the positioning methods set by setPreferredPositioningMethods().

See also setPreferredPositioningMethods().

### `[pure virtual slot]` void QGeoPositionInfoSource::requestUpdate(int timeout = 0)

Attempts to get the current position and emit positionUpdated() with this information. If the current position cannot be found within the given timeout (in milliseconds) or if timeout is less than the value returned by minimumUpdateInterval(), updateTimeout() is emitted.

If the timeout is zero, the timeout defaults to a reasonable timeout period as appropriate for the source.

This does nothing if another update request is in progress. However it can be called even if startUpdates() has already been called and regular updates are in progress.

If the source uses multiple positioning methods, it tries to get the current position from the most accurate positioning method within the given timeout.

### `[virtual]` void QGeoPositionInfoSource::setPreferredPositioningMethods(PositioningMethods methods)

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.

See also preferredPositioningMethods() and supportedPositioningMethods().

### `[pure virtual slot]` void QGeoPositionInfoSource::startUpdates()

Starts emitting updates at regular intervals as specified by setUpdateInterval().

If setUpdateInterval() has not been called, the source will emit updates as soon as they become available.

An updateTimeout() signal will be emitted if this QGeoPositionInfoSource subclass determines that it will not be able to provide regular updates. This could happen if a satellite fix is lost or if a hardware error is detected. Position updates will recommence if the data becomes available later on. The updateTimeout() signal will not be emitted again until after the periodic updates resume.

On iOS, starting from version 8, Core Location framework requires additional entries in the application's Info.plist with keys NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription and a string to be displayed in the authorization prompt. The key NSLocationWhenInUseUsageDescription is used when requesting permission to use location services while the app is in the foreground. The key NSLocationAlwaysUsageDescription is used when requesting permission to use location services whenever the app is running (both the foreground and the background). If both entries are defined, NSLocationWhenInUseUsageDescription has a priority in the foreground mode.

### `[pure virtual slot]` void QGeoPositionInfoSource::stopUpdates()

Stops emitting updates at regular intervals.

### `[pure virtual]` PositioningMethods QGeoPositionInfoSource::supportedPositioningMethods() const

Returns the positioning methods available to this source.

See also setPreferredPositioningMethods().

### `[signal]` void QGeoPositionInfoSource::updateTimeout()

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.

While the triggering of this signal may be considered an error condition, it does not imply the emission of the `error()` signal. Only the emission of `updateTimeout()` is required to indicate a timeout.