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 特性。

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

The RSSI View tab shows the signal strength of satellites in view using the signalStrength 特性。

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 状态 block shows the current mode or the last error.

The application operates in three different modes:

应用程序模式 描述
运行 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.

运行范例

要运行范例从 Qt Creator ,打开 Welcome 模式,然后选择范例从 Examples 。更多信息,拜访 构建和运行范例 .

检索当前位置

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 特性。

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

检索卫星信息

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 模块配准

CMake 构建

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

qt_add_qml_module(satelliteinfo
    URI SatelliteInformation
    VERSION 1.0
    QML_FILES
        Button.qml
        Main.qml
        RssiView.qml
        PositionAndStatus.qml
        SkyView.qml
        ViewSwitch.qml
)
					
qmake 构建

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

qml_resources.files = \
    qmldir \
    Button.qml \
    Main.qml \
    RssiView.qml \
    PositionAndStatus.qml \
    SkyView.qml \
    ViewSwitch.qml
qml_resources.prefix = /qt/qml/SatelliteInformation
RESOURCES += qml_resources
					

范例工程 @ code.qt.io