SatelliteInfo (QML)#

The SatelliteInfo example shows the available satellites using Sky View or RSSI View and the user’s current position. The satellites currently contributing to the GPS fix are marked as pink.

This example demonstrates the usage of Qt Positioning QML API :

The example shows satellite information in two different tabs. The data is taken from the SatelliteSource::satellitesInView and SatelliteSource::satellitesInUse properties.

../_images/example-skyview.png

The Sky View tab shows the relative satellite positions using the Azimuth and Elevation attributes .

../_images/example-rssiview.png

The RSSI View tab shows the signal strength of satellites in view using the signalStrength property.

In both cases, the displayed numbers are the individual satellite identifiers . The satellites that are currently used to calculate the GPS fix are marked pink.

The Current Position block below the satellite information uses PositionSource::position property to show the current latitude and longitude.

The Status block shows the current mode or the last error.

The application operates in three different modes:

Application mode

Description

Running

The application continuously queries the system for satellite and position updates. When new data is available it will be displayed.

Stopped

The application stops updating the satellite and position information.

Single

The application makes a single satellite and position update request.

The application automatically switches into a simulation mode if the platform does not provide satellite or position information. The simulation mode uses an NMEA plugin with pre-recorded NMEA data.

Running the Example#

To run the example from Qt Creator , open the Welcome mode and select the example from Examples. For more information, visit Building and Running an Example .

Retrieving Current Position#

The current position is retrieved from the PositionSource QML object. The onPositionChanged handler is used to receive position updates. The string representations of latitude and longitude are extracted from the coordinate property.

PositionSource {
    id: positionSource
    name: root.simulation ? "nmea" : ""        onPositionChanged: {
    let posData = position.coordinate.toString().split(", ")
    positionAndStatus.latitudeString = posData[0]
    positionAndStatus.longitudeString = posData[1]
}        }

Retrieving Satellite Information#

Similarly to the position, the current satellite information is retrieved from the SatelliteSource QML object. The onSatellitesInViewChanged and onSatellitesInUseChanged handlers are used to get the updated satellites in view and satellites in use respectively. The data is then combined into a single model, which is passed to both Sky View and RSSI View tabs.

SatelliteSource {
    id: satelliteSource
    name: root.simulation ? "nmea" : ""        onSatellitesInViewChanged: root.updateModel()
onSatellitesInUseChanged: {
    root.inUseIds.clear()
    for (var i = 0; i < satellitesInUse.length; ++i)
        root.inUseIds.add(satellitesInUse[i].satelliteIdentifier)

    root.updateModel()
}        }

QML Module Registration#

CMake Build#

For a CMake-based build, we need to add the following to the CMakeLists.txt:

qmake Build#

For a qmake build, we need to modify the satelliteinfo.pro file in the following way:

Example project @ code.qt.io