SatelliteSource QML Type
SatelliteSource 类提供卫星信息。更多内容...
| Import Statement: | import QtPositioning |
| Since: | Qt 6.5 |
属性
- active : bool
- name : string
- parameters : list<PluginParameter>
- satellitesInUse : list<geoSatelliteInfo>
- satellitesInView : list<geoSatelliteInfo>
- sourceError : enumeration
- updateInterval : int
- valid : bool
方法
- var backendProperty(string name)
- bool setBackendProperty(string name, var value)
- void start()
- void stop()
- void update(int timeout)
详细说明
SatelliteSource 类提供有关正在使用中的卫星和可见卫星的信息。该类是QGeoSatelliteInfoSource 的 QML 表示形式。
与它的 C++ 对应类一样,该类支持不同的插件。使用name 属性指定要使用的插件名称,并在需要时提供PluginParameter。如果未设置name 属性,则将使用默认插件。有关可用插件的更多信息,请参阅Qt Positioning Plugins。
使用valid 属性来检查 SatelliteSource 的状态。
使用updateInterval 属性来指定应用程序希望接收卫星信息更新的频率。可通过start()、stop() 和update() 方法来控制 SatelliteSource 的运行,此外,active 属性在设置后其效果等同于调用start() 或stop()。
当 SatelliteSource 处于活动状态时,可通过satellitesInView 和satellitesInUse 属性获取卫星信息更新。
如果在卫星信息更新过程中发生错误,请使用sourceError 属性获取实际的错误代码。
使用示例
以下示例展示了一个 SatelliteSource,它使用NMEA插件每秒接收一次卫星信息更新,并将可见卫星数和正在使用的卫星数打印到控制台。
SatelliteSource {
id: source
name: "nmea"
active: true
updateInterval: 1000
PluginParameter { name: "nmea.source"; value: "serial:/dev/ttyACM0" }
onSatellitesInUseChanged: {
console.log("Satellites in use:", source.satellitesInUse.length)
}
onSatellitesInViewChanged: {
console.log("Satellites in view:", source.satellitesInView.length)
}
}另请参阅 QGeoSatelliteInfoSource 、PluginParameter 和geoSatelliteInfo 。
属性文档
active : bool
该属性用于指示卫星源是否处于活动状态。将该属性设置为false 等同于调用stop ,而将其设置为true 则等同于调用start 。
name : string
该属性存储了当前提供卫星信息的插件的唯一内部名称。
设置该属性会使“SatelliteSource ”使用特定的后端插件。如果在修改 name 属性时“SatelliteSource ”处于活动状态,它将变为非活动状态。如果无法加载指定的后端,卫星源将失效。
更改 name 属性可能会导致updateInterval 属性随之改变。
parameters : list<PluginParameter> [default read-only]
该属性保存了插件参数的列表。
另请参阅 PluginParameter 。
satellitesInUse : list<geoSatelliteInfo> [read-only]
该属性存储了当前正在使用的卫星列表。这些卫星用于获取“定位结果”——即用于确定当前位置的卫星。
satellitesInView : list<geoSatelliteInfo> [read-only]
该属性保存了当前可见的卫星列表。
sourceError : enumeration [read-only]
该属性存储后端数据提供程序最近发生的错误。
| 常量 | 描述 |
|---|---|
SatelliteSource.AccessError | 由于应用程序缺少所需的权限,与卫星后端建立连接失败。 |
SatelliteSource.ClosedError | 卫星后端关闭了连接,例如当用户将定位服务关闭时,就会发生这种情况。 |
SatelliteSource.NoError | 未发生任何错误。 |
SatelliteSource.UnknownSourceError | 发生了一个未识别的错误。 |
SatelliteSource.UpdateTimeoutError | 未能在指定的超时时间内检索到卫星信息。 |
updateInterval : int
该属性存储更新之间所需的间隔(单位为毫秒)。
valid : bool [read-only]
如果SatelliteSource 对象已获取一个有效的后端插件来提供数据,则该属性值为true ;否则,该属性值为false 。
应用程序应检查此属性,以确定运行时平台上是否提供并启用了卫星信息,并据此作出相应反应。
方法文档
var backendProperty(string name)
如果存在名为name 的后端特定属性,则返回该属性的值。否则,包括在未初始化的SatelliteSource 上调用时,返回值将无效。
另请参阅 setBackendProperty()。
bool setBackendProperty(string name, var value)
将名为name 的后端特定属性设置为value 。成功时返回true,否则返回false,包括在未初始化的SatelliteSource 上调用时。
另请参阅 backendProperty()。
void start()
向卫星源请求更新。如果设置了updateInterval ,则使用该间隔;否则使用默认间隔。如果没有可用源,此方法将不起作用。
另请参阅 stop()、update() 和active 。
void stop()
停止从卫星源获取更新。如果没有可用源或源处于非活动状态,此方法将不起作用。
另请参阅 start()、update() 以及active 。
void update(int timeout = 0)
一种便捷的方法,用于向卫星源请求单次更新。如果没有可用的源,此方法将不起作用。
如果卫星源未处于活动状态,则会将其激活,直至接收到更新,或请求超时为止。请求超时时间因插件而异。
timeout 以毫秒为单位指定。如果timeout 为零(默认值),则会根据数据源情况默认采用一个合理的超时时间。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.