QGeoSatelliteInfoSource Class

QGeoSatelliteInfoSource 类是用于分发卫星信息更新的抽象基类。更多

头文件: #include <QGeoSatelliteInfoSource>
CMake: find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)
qmake: QT += positioning
继承: QObject
继承于:

QNmeaSatelliteInfoSource

公共类型

enum Error { AccessError, ClosedError, NoError, UnknownSourceError, UpdateTimeoutError }

属性

公共功能

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 &parameters, QObject *parent)
QGeoSatelliteInfoSource *createSource(const QString &sourceName, QObject *parent)
(since Qt 5.14) QGeoSatelliteInfoSource *createSource(const QString &sourceName, const QVariantMap &parameters, 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 服务中使用该类,请参阅Qt Positioning on Android

成员类型文档

enum QGeoSatelliteInfoSource::Error

错误枚举表示可能发生的错误。

常量说明
QGeoSatelliteInfoSource::AccessError0由于应用程序缺乏所需的权限,与卫星后端的连接设置失败。
QGeoSatelliteInfoSource::ClosedError1卫星后端关闭了连接,例如在用户将定位服务切换为关闭的情况下。该对象失效,应予以删除。稍后可通过调用createDefaultSource() 创建新的卫星源。
QGeoSatelliteInfoSource::NoError2未发生错误。
QGeoSatelliteInfoSource::UnknownSourceError-1发生不明错误。
QGeoSatelliteInfoSource::UpdateTimeoutError3在指定超时内无法检索到当前卫星信息。

属性文档

[read-only] minimumUpdateInterval : const int

该属性包含检索卫星更新所需的最短时间(毫秒)。

这是setUpdateInterval() 和requestUpdate() 所接受的最小值。

访问功能:

virtual int minimumUpdateInterval() const = 0

[bindable] updateInterval : int

注意: 该属性支持QProperty 绑定。

该属性用于保存请求的每次更新间隔(以毫秒为单位)。

如果未设置更新间隔(或设置为 0),信息源将根据需要提供更新。

如果设置了更新间隔,源将以尽可能接近请求的间隔提供更新。如果请求的更新间隔小于minimumUpdateInterval() ,则会使用最小更新间隔。

更新间隔的更改将在可行的情况下尽快进行,但更改所需的时间可能因实现方式而异。至于上一间隔的时间是否算作新间隔的一部分,也与实现有关。

此属性的默认值为 0。

注意: 子类实现必须调用 setUpdateInterval() 的基本实现,以便 updateInterval() 返回正确的值。

成员函数文档

[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 &parameters, 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 &parameters, 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() 返回的值,则会发出包含UpdateTimeoutErrorerrorOccurred() 信号。

如果超时为零,超时默认为适合源的合理超时时间。

如果另一个更新请求正在进行中,则此操作不起任何作用。不过,即使startUpdates() 已被调用且正在进行常规更新,也可以调用该方法。

注: 自 Qt6 起,在请求卫星信息之前,该方法总是将上次错误重置为NoError

注: 要了解如何通过 Android 服务使用此方法,请参阅Qt Positioning on Android

[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 服务中使用此方法,请参阅Qt Positioning on Android

另请参阅 satellitesInViewUpdated() 和satellitesInUseUpdated()。

[pure virtual slot] void QGeoSatelliteInfoSource::stopUpdates()

停止定期更新。

© 2025 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.