本页内容

Qt Positioning

Qt Positioning API 通过 QML 和 C++ 接口提供定位信息。

目前,该 API 支持Android、iOS、macOS、Linux 和Windows平台(需将 GPS 接收器作为串行端口暴露,以提供 NMEA 报文,或使用Windows.Devices.Geolocation )。

概述

Qt Positioning API 允许您利用多种可能的来源(包括卫星、Wi-Fi 或文本文件)来确定位置。随后,这些信息可用于在地图上确定位置等操作。此外,您还可以使用该 API 检索卫星信息并执行基于区域的监控。

使用该模块

QML API

该模块的 QML 类型可通过 `QtPositioning ` 导入使用。要使用这些类型,请在您的 .qml 文件中添加以下导入语句:

import QtPositioning

C++ API

要使用 Qt 模块的 C++ API,需要链接该模块库,既可以直接链接,也可以通过其他依赖项间接链接。包括CMake和qmake 在内的多种构建工具都对此提供了专门支持。

使用 CMake 构建

使用find_package() 命令在Qt6 软件包中定位所需的模块组件:

find_package(Qt6 REQUIRED COMPONENTS Positioning)
target_link_libraries(mytarget PRIVATE Qt6::Positioning)

更多详细信息,请参阅“使用 CMake 构建”概述。

使用 qmake 构建

要配置模块以便使用 qmake 进行构建,请在项目的 .pro 文件中将该模块作为QT 变量的值添加:

QT += positioning

权限

从 Qt 6.6 开始,Qt Positioning 模块使用新的QPermission API 来处理location 权限。这意味着 Qt 本身不再查询这些权限,因此需要由客户端应用程序直接进行查询。

请参阅“应用程序权限”页面,了解如何将新的QPermission API集成到应用程序中的示例。

文章与指南

示例

参考

模块演变

Qt Positioning 中列出了为 Qt 6 系列所做的模块 API 和功能方面的重大变更。

许可证

Qt Positioning Qt 由The Qt Company 提供商业许可。此外,它还提供自由软件许可。自 Qt 5.4 起,这些自由软件许可包括GNU 较宽松通用公共许可证第 3 版或GNU 通用公共许可证第 2 版。更多详细信息请参阅Qt 许可。

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