SatelliteInfo (C++/QML)

The SatelliteInfo example shows the available satellites at the user’s current position and marks the satellites currently contributing to the GPS fix as pink.

Key Qt Positioning classes used in this example:

  • QGeoSatelliteInfo

  • QGeoSatelliteInfoSource


The example displays the signal strength of all satellites in view. Any satellite that is currently used to calculate the GPS fix is marked pink. The number at the bottom of each signal bar is the individual satellite identifier.

The application operates in three different modes:

Application mode



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


The application stops updating the satellite information.


The application makes a single update request with a timeout of 10s. The display remains empty until the request was answered by the system.

If the platform does not provide satellite information, the application automatically switches into a demo mode, whereby it continuously switches between predefined sets of satellite 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.

Satellite Info Model

The key part of this example is the SatelliteModel data model. It represents the information about the satellites. It uses the Q_PROPERTY and QML_ELEMENT macros, so that it can be available from QML.

class SatelliteModel(QAbstractListModel, QQmlParserStatus):

    Q_PROPERTY(bool running READ running WRITE setRunning NOTIFY runningChanged)
    Q_PROPERTY(bool satelliteInfoAvailable READ canProvideSatelliteInfo NOTIFY canProvideSatelliteInfoChanged)
    Q_PROPERTY(int entryCount READ entryCount NOTIFY entryCountChanged)
    Q_PROPERTY(bool singleRequestMode READ isSingleRequest WRITE setSingleRequest NOTIFY singleRequestChanged)
# public
    SatelliteModel = explicit(QObject parent = 0)
    enum {
        IdentifierRole = Qt.UserRole + 1,

    #From QAbstractListModel
    rowCount = int(QModelIndex parent)
    data = QVariant(QModelIndex index, int role)
QByteArray> = QHash<int,()
    #From QQmlParserStatus
    def classBegin(): pass
    def componentComplete():        signals:
    def runningChanged():
    def entryCountChanged():
    def errorFound(code):
    def canProvideSatelliteInfoChanged():
    def singleRequestChanged():
slots: = public()
    def clearModel():
    def updateDemoData():

The SatelliteModel object creates an instance of QGeoSatelliteInfoSource using the createDefaultSource() method. Once the source is created, the satellitesInViewUpdated() and satellitesInUseUpdated() signals are used to notify about the changes in satellite information.

def __init__(self, parent):
    QAbstractListModel(parent), source(0), m_componentCompleted(False), m_running(False),
    m_runningRequested(False), demo(False), isSingle(False), singleRequestServed(False)

    source = QGeoSatelliteInfoSource.createDefaultSource(self)
    if (not demo and not source) {
        qWarning() << "No satellite data source found. Changing to demo mode."
        demo = True

    if (not demo) {
        connect(source, SIGNAL(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)),
                self, SLOT(satellitesInViewUpdated(QList<QGeoSatelliteInfo>)))
        connect(source, SIGNAL(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)),
                self, SLOT(satellitesInUseUpdated(QList<QGeoSatelliteInfo>)))
        connect(source, SIGNAL(errorOccurred(QGeoSatelliteInfoSource.Error)),
                self, SLOT(error(QGeoSatelliteInfoSource.Error)))

    if (demo) {
        timer = QTimer(self)
        connect(timer, SIGNAL(timeout()), self, SLOT(updateDemoData()))

The aforementioned signals provide the lists of QGeoSatelliteInfo objects that represent satellites in view and satellites in use, respectively. This data is used to update the model.

def satellitesInViewUpdated(self, infos):

    if (not running())
    oldEntryCount = knownSatellites.count()
satelliteIdsInUpdate = QSet()
    for info in infos:
    toBeRemoved = knownSatelliteIds - satelliteIdsInUpdate
    #We reset the model as in reality just about all entry values change
    #and there are generally a lot of inserts and removals each time
    #Hence we don't bother with complex model update logic beyond resetModel()
    knownSatellites = infos
    #sort them for presentation purposes
    std::sort(knownSatellites.begin(), knownSatellites.end())
    #remove old "InUse" data
    #new satellites are by default not in "InUse"
    #existing satellites keep their "inUse" state
    satellitesInUse -= toBeRemoved
    knownSatelliteIds = satelliteIdsInUpdate
    if (oldEntryCount != knownSatellites.count())

def satellitesInUseUpdated(self, infos):

    if (not running())
    for info in infos:

If the satellite info source is not available, demo data is used to simulate satellite information updates.

def updateDemoData(self):

    flag = True()
satellites = QList()
    if (flag) {
        for i in range(0, 5):
            info = QGeoSatelliteInfo()
            info.setSignalStrength(20 + 20i)

        for i in range(0, 9):
            info = QGeoSatelliteInfo()
            info.setSignalStrength(20 + 10i)

    flag ? satellitesInUseUpdated(QList<QGeoSatelliteInfo>() <<
         : satellitesInUseUpdated(QList<QGeoSatelliteInfo>() <<
    flag = not flag
    if (isSingleRequest() and not singleRequestServed) {
        singleRequestServed = True

The model is later used in QML to visualize the data.

Exposing the Model to QML

To expose SatelliteModel to QML, we use the QML_ELEMENT macro. See the QQmlEngine class documentation for more details on it.

To make the type available in QML, we need to update our build accordingly.

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 file in the following way:

Example project @