Qt Positioning 插件
Qt Positioning 主要通过插件提供其大部分功能。本文档概述了如何开发一个新的位置插件。
默认插件
Qt 默认已自带一些插件,包括:
| android | 封装了Android定位子系统。仅在 Android 系统上可用。 |
| corelocation | 封装了 iOS 和 macOS 的定位子系统。仅在支持 corelocation 的 Apple 平台上可用。 |
| geoclue2 | 一个GeoClue v2后端,为 GeoClue v2 D-Bus 服务提供接口。 |
| gypsy | 一个Gypsy后端,为 Gypsy 守护进程提供接口。 |
| winrt | 封装了 WinRT 定位子系统。仅在 WinRT 和 Windows 10 上可用。 |
| nmea | 一个NMEA后端,用于解析来自 GPS 接收器的 NMEA 数据流以提供位置更新。该插件可使用串口、套接字或文件作为数据源。 |
| positionpoll | 一个仅通过轮询位置更新来提供区域监控功能的后端。 |
插件描述
每个插件均由一个 JSON 文件描述。该 JSON 文件描述了插件的功能和版本。以下是 positionpoll 插件所使用的 JSON 文件示例:
{
"Keys": ["positionpoll"],
"Provider": "positionpoll",
"Position": false,
"Satellite": false,
"Monitor": true,
"Priority": 1000,
"Testable": true
}各条目的含义如下:
| 键 | 描述 |
|---|---|
| 键 | 插件的唯一名称/键。每个位置插件必须具有唯一的名称。 |
| 提供者 | 服务的提供者名称。多个插件可能具有相同的名称。在这种情况下,将使用“版本”字符串来进一步区分这些插件。 |
| 位置 | 如果插件实现了QGeoPositionInfoSource ,请将其设置为true 。 |
| 卫星 | 如果插件实现了QGeoSatelliteInfoSource ,则将其设置为true 。 |
| 监视 | 如果插件实现了QGeoAreaMonitorSource ,则将其设置为true 。 |
| 优先级 | 插件的优先级。如果多个插件具有相同的提供程序名称,则将使用优先级最高的插件。 |
实现插件
插件开发者需要继承QGeoPositionInfoSourceFactory 类,并重写其中一个或多个函数。如果插件不支持某项特定功能,该函数应返回0或使用默认实现。
© 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.