QGeoSatelliteInfoSource Class
QGeoSatelliteInfoSource 类是用于分发卫星信息更新的抽象基类。更多内容...
| 头文件: | #include <QGeoSatelliteInfoSource> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Positioning) target_link_libraries(mytarget PRIVATE Qt6::Positioning) |
| qmake: | QT += positioning |
| 继承自: | QObject |
| 被继承者: |
公共类型
| enum | Error { AccessError, ClosedError, NoError, UnknownSourceError, UpdateTimeoutError } |
属性
- minimumUpdateInterval : int
- updateInterval : int
公共函数
| QGeoSatelliteInfoSource(QObject *parent) | |
| virtual | ~QGeoSatelliteInfoSource() |
(since 6.2) virtual QVariant | backendProperty(const QString &name) const |
| QBindable<int> | bindableUpdateInterval() |
| virtual QGeoSatelliteInfoSource::Error | error() const = 0 |
| virtual int | minimumUpdateInterval() const = 0 |
(since 6.2) virtual bool | setBackendProperty(const QString &name, const QVariant &value) |
| virtual void | setUpdateInterval(int msec) |
| QString | sourceName() const |
| int | updateInterval() const |
公共槽位
| virtual void | requestUpdate(int timeout = 0) = 0 |
| virtual void | startUpdates() = 0 |
| virtual void | stopUpdates() = 0 |
信号
| void | errorOccurred(QGeoSatelliteInfoSource::Error satelliteError) |
| void | satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites) |
| void | satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites) |
静态公共成员
| QStringList | availableSources() |
| QGeoSatelliteInfoSource * | createDefaultSource(QObject *parent) |
(since Qt 5.14) QGeoSatelliteInfoSource * | createDefaultSource(const QVariantMap ¶meters, QObject *parent) |
| QGeoSatelliteInfoSource * | createSource(const QString &sourceName, QObject *parent) |
(since Qt 5.14) QGeoSatelliteInfoSource * | createSource(const QString &sourceName, const QVariantMap ¶meters, QObject *parent) |
详细说明
静态函数QGeoSatelliteInfoSource::createDefaultSource() 会创建一个适合该平台的默认卫星数据源(如果存在的话)。否则,将检查可用的QGeoPositionInfoSourceFactory 插件,以查找具有可用卫星数据源的插件。
调用startUpdates()和stopUpdates()可启动或停止定期更新,或调用requestUpdate()请求单次更新。当有更新可用时,将触发satellitesInViewUpdated()和/或satellitesInUseUpdated()。
如果需要定期卫星更新,可以使用setUpdateInterval() 来指定这些更新的发布频率。如果未指定间隔,则会在更新可用时立即提供。例如:
// Emit updates every 10 seconds if available
QGeoSatelliteInfoSource *source = QGeoSatelliteInfoSource::createDefaultSource(0);
if (source)
source->setUpdateInterval(10000);要移除先前设置的更新间隔,请调用setUpdateInterval() 并传入值 0。
注意: 卫星数据源 可能对更新间隔有最小值要求,具体由minimumUpdateInterval() 返回的值决定。
注意:若要在 Android 服务中使用此类,请参阅Android 上的Qt Positioning 。
成员类型文档
enum QGeoSatelliteInfoSource::Error
Error 枚举表示可能发生的错误。
| 常量 | 值 | 描述 |
|---|---|---|
QGeoSatelliteInfoSource::AccessError | 0 | 由于应用程序缺乏所需的权限,与卫星后端的连接建立失败。 |
QGeoSatelliteInfoSource::ClosedError | 1 | 卫星后端关闭了连接,例如当用户将位置服务关闭时就会发生这种情况。该对象已失效,应予删除。稍后可通过调用createDefaultSource() 创建一个新的卫星源。 |
QGeoSatelliteInfoSource::NoError | 2 | 未发生任何错误。 |
QGeoSatelliteInfoSource::UnknownSourceError | -1 | 发生了一个未识别的错误。 |
QGeoSatelliteInfoSource::UpdateTimeoutError | 3 | 无法在指定的超时时间内检索到当前卫星信息。 |
属性文档
[read-only] minimumUpdateInterval : int
该属性表示检索卫星更新所需的最短时间(以毫秒为单位)。
这是setUpdateInterval()和requestUpdate()函数所接受的最小值。
访问函数:
| virtual int | minimumUpdateInterval() const = 0 |
[bindable] updateInterval : int
注意:此 属性支持QProperty 绑定。
该属性存储每次更新之间所需的间隔(以毫秒为单位)。
如果未设置更新间隔(或设置为 0),源将根据需要提供更新。
如果设置了更新间隔,源将以尽可能接近请求间隔的间隔提供更新。如果请求间隔小于minimumUpdateInterval(),则改用最小间隔。
更新间隔的更改将在实际可行的情况下尽快生效,但更改所需的时间可能因实现而异。从上一个间隔开始的已过去时间是否计入新间隔,也取决于具体实现。
该属性的默认值为 0。
注意:子类 实现必须调用 setUpdateInterval() 的基类实现,以确保 updateInterval() 返回正确的值。
访问函数:
| int | updateInterval() const |
| virtual void | setUpdateInterval(int msec) |
成员函数文档
[explicit] QGeoSatelliteInfoSource::QGeoSatelliteInfoSource(QObject *parent)
创建一个具有指定parent 的卫星源。
[virtual noexcept] QGeoSatelliteInfoSource::~QGeoSatelliteInfoSource()
摧毁了卫星源。
[static] QStringList QGeoSatelliteInfoSource::availableSources()
返回一个可用源插件的列表,其中包括系统默认后端(如果存在的话)。
[virtual, since 6.2] QVariant QGeoSatelliteInfoSource::backendProperty(const QString &name) const
如果存在名为name 的后端特定属性,则返回该属性的值;否则,返回的值将无效。
该函数在 Qt 6.2 中引入。
另请参阅 setBackendProperty 。
[static] QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(QObject *parent)
创建并返回一个具有指定parent 的源,该源从系统的默认卫星更新信息源或可用优先级最高的插件中读取数据。
如果系统没有默认卫星数据源、未找到有效的插件,或者用户无权访问卫星数据,则返回nullptr 。
[static, since Qt 5.14] QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createDefaultSource(const QVariantMap ¶meters, QObject *parent)
创建并返回一个卫星数据源,该数据源使用给定的parent ,从系统的默认卫星数据源或可用优先级最高的插件中读取数据。
如果系统没有默认卫星数据源、未找到有效的插件,或者用户无权访问卫星信息,则返回nullptr 。
此方法将parameters 传递给工厂以配置数据源。
该函数于 Qt 5.14 中引入。
[static] QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, QObject *parent)
通过加载名为sourceName 的插件,创建并返回一个具有指定parent 的源。
如果找不到该插件,则返回nullptr 。
[static, since Qt 5.14] QGeoSatelliteInfoSource *QGeoSatelliteInfoSource::createSource(const QString &sourceName, const QVariantMap ¶meters, QObject *parent)
通过加载名为sourceName 的插件,创建并返回一个具有给定parent 的卫星源。
如果找不到该插件,则返回nullptr 。
此方法将 `parameters ` 传递给工厂以配置源。
该函数于 Qt 5.14 中引入。
[pure virtual] QGeoSatelliteInfoSource::Error QGeoSatelliteInfoSource::error() const
返回最近发生的错误。
注意:自 Qt6起 ,每次调用 `startUpdates()` 或 `requestUpdate()` 时,最后一次错误都会被重置。
[signal] void QGeoSatelliteInfoSource::errorOccurred(QGeoSatelliteInfoSource::Error satelliteError)
该信号在发生错误后发出。satelliteError 参数描述了发生的错误类型。
[pure virtual slot] void QGeoSatelliteInfoSource::requestUpdate(int timeout = 0)
尝试获取当前卫星信息,并利用该信息触发satellitesInViewUpdated()和satellitesInUseUpdated()。如果在给定的timeout (以毫秒为单位)内无法找到当前卫星信息,或者timeout 小于minimumUpdateInterval()返回的值,则会触发带有UpdateTimeoutError 的errorOccurred()信号。
如果超时时间为零,则超时时间将默认设置为适合该源的合理超时周期。
如果另一个更新请求正在进行中,此操作将不产生任何效果。但是,即使已经调用了startUpdates() 且常规更新正在进行中,也可以调用此方法。
注意:自 Qt6起 ,该方法在请求卫星信息之前,总会将最后一个错误重置为NoError 。
注意:要 了解如何在 Android 服务中使用此方法,请参阅Android 上的Qt Positioning 。
[signal] void QGeoSatelliteInfoSource::satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites)
如果调用了startUpdates() 或requestUpdate(),当当前正在使用的卫星数量有更新时,将触发此信号。
这些卫星用于“定位”——即用于确定当前位置。
satellites 参数保存了当前正在使用的卫星。
[signal] void QGeoSatelliteInfoSource::satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites)
如果调用了startUpdates()或requestUpdate(),当当前可见的卫星有更新时,将触发此信号。
satellites 参数包含当前可见的卫星。
[virtual, since 6.2] bool QGeoSatelliteInfoSource::setBackendProperty(const QString &name, const QVariant &value)
将名为name 的后端特定属性设置为value 。成功时返回true ,否则返回false 。后端特定属性可用于在运行时配置卫星信息子系统的行为。
该函数在 Qt 6.2 中引入。
另请参阅 backendProperty 。
QString QGeoSatelliteInfoSource::sourceName() const
返回当前正在使用的卫星源实现的唯一名称。
该名称与传递给createSource()以创建特定卫星源实现的新实例时所用的名称相同。
[pure virtual slot] void QGeoSatelliteInfoSource::startUpdates()
开始以固定间隔发送更新。每当有新的卫星信息可用时,系统就会提供更新。
如果无法获取卫星信息或发生其他形式的超时,可能会以空参数列表触发satellitesInViewUpdated()和satellitesInUseUpdated()信号。
注意:自 Qt6起 ,该方法在开始更新前会始终将最后一个错误重置为NoError 。
注意:要 了解如何在 Android 服务中使用此方法,请参阅Android 上的Qt Positioning 。
另请参阅 satellitesInViewUpdated() 和satellitesInUseUpdated()。
[pure virtual slot] void QGeoSatelliteInfoSource::stopUpdates()
停止按固定间隔发送更新。
© 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.