QPlaceManager Class
QPlaceManager 类提供了一个接口,允许客户端访问存储在特定后端中的位置。更多内容...
| Header: | #include <QPlaceManager> |
| qmake: | QT += location |
| Inherits: | QObject |
公共函数
| virtual | ~QPlaceManager() |
| QPlaceCategory | category(const QString &categoryId) const |
| QList<QPlaceCategory> | childCategories(const QString &parentId = QString()) const |
| QStringList | childCategoryIds(const QString &parentId = QString()) const |
| QPlace | compatiblePlace(const QPlace &original) const |
| QPlaceContentReply * | getPlaceContent(const QPlaceContentRequest &request) const |
| QPlaceDetailsReply * | getPlaceDetails(const QString &placeId) const |
| QPlaceReply * | initializeCategories() |
| QList<QLocale> | locales() const |
| QString | managerName() const |
| int | managerVersion() const |
| QPlaceMatchReply * | matchingPlaces(const QPlaceMatchRequest &request) const |
| QString | parentCategoryId(const QString &categoryId) const |
| QPlaceIdReply * | removeCategory(const QString &categoryId) |
| QPlaceIdReply * | removePlace(const QString &placeId) |
| QPlaceIdReply * | saveCategory(const QPlaceCategory &category, const QString &parentId = QString()) |
| QPlaceIdReply * | savePlace(const QPlace &place) |
| QPlaceSearchReply * | search(const QPlaceSearchRequest &request) const |
| QPlaceSearchSuggestionReply * | searchSuggestions(const QPlaceSearchRequest &request) const |
| void | setLocale(const QLocale &locale) |
| void | setLocales(const QList<QLocale> &locales) |
信号
| void | categoryAdded(const QPlaceCategory &category, const QString &parentId) |
| void | categoryRemoved(const QString &categoryId, const QString &parentId) |
| void | categoryUpdated(const QPlaceCategory &category, const QString &parentId) |
| void | dataChanged() |
| void | errorOccurred(QPlaceReply *reply, QPlaceReply::Error error, const QString &errorString = QString()) |
| void | finished(QPlaceReply *reply) |
| void | placeAdded(const QString &placeId) |
| void | placeRemoved(const QString &placeId) |
| void | placeUpdated(const QString &placeId) |
详细说明
下表概述了 QPlaceManager 提供的功能
| 功能 | 描述 |
|---|---|
| 搜索地点 | 通过使用搜索词和搜索区域等一组参数,可以向用户返回相关的地点。 |
| 分类 | 地点可归类到不同的类别中。管理员可管理这些类别。 |
| 搜索词建议 | 当输入不完整的搜索词时,系统会提供一系列可能的搜索词。 |
| 推荐 | 针对某个现有地点,系统可向用户推荐一组相似的地点。 |
| 丰富内容 | 可以分页检索图片、评论等丰富内容。 |
| 地点或类别管理 | 可以保存和删除地点及分类。在进行这些操作时,系统可发送通知。 |
| 本地化 | 可指定不同的区域设置,以不同语言返回地点数据。 |
获取 QPlaceManager 实例
QGeoServiceProvider 简化了 QPlaceManager 的创建过程。有关如何创建管理器的示例,请参阅“初始化管理器”。
异步接口
QPlaceManager 类对包含位置信息的数据存储进行了抽象。QPlaceManager 提供的函数主要为异步操作,并遵循请求-响应模型。通常,向管理器发出一个包含一组不同参数的请求,并创建一个响应对象。 该响应对象具有一个信号,用于在请求完成时发出通知;一旦完成,响应中将包含请求的结果,以及可能出现的任何错误(如有)。
异步请求通常按以下方式处理:
//1) 发起相应请求
QPlaceSearchRequest searchRequest;
searchRequest.setSearchTerm("ice cream");
searchRequest.setSearchArea(QGeoCircle(QGeoCoordinate(12.34, 56.78)));
//2) 使用管理器发起请求并获取响应对象
QPlaceSearchReply*searchReply= manager->search(searchRequest);
//3) 将响应对象连接到一个槽,该槽将在操作完成后被调用
connect(searchReply, &QPlaceSearchReply::finished,
this, &RequestHandler::processSearchReply);
...
...
//4) 由槽函数对操作结果进行适当处理
voidprocessSearchReply() {
if(searchReply->error()==QPlaceReply::NoError) {
for(constQPlaceSearchResult&result: searchReply->results()) {
if(result.type()==QPlaceSearchResult::PlaceResult)
qDebug() << "Title:" << result.title();
}
}
//5) 操作完成后释放 reply 对象。
searchReply->deleteLater();
searchReply=nullptr;
}请参阅“常用操作”部分,其中列举了演示如何使用 QPlaceManager 的示例。
类别:初始化
在应用程序启动过程中,应调用initializeCategories() 函数来设置分类。初始化分类后,即可使用以下函数:
- QPlaceManager::childCategories()
- QPlaceManager::category()
- QPlaceManager::parentCategoryId()
- QPlaceManager::childCategoryIds();
如果需要刷新或重新加载分类,可以再次调用initializeCategories()函数。
成员函数文档
[virtual noexcept] QPlaceManager::~QPlaceManager()
销毁该管理器。该析构函数由QGeoServiceProvider 在内部使用,应用程序代码中绝不应调用它。
QPlaceCategory QPlaceManager::category(const QString &categoryId) const
返回与给定的categoryId 对应的类别。
[signal] void QPlaceManager::categoryAdded(const QPlaceCategory &category, const QString &parentId)
当category 被添加到管理器的数据存储中时,会发出此信号。category 的父对象由parentId 指定。
仅支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
另请参阅 dataChanged()。
[signal] void QPlaceManager::categoryRemoved(const QString &categoryId, const QString &parentId)
当与 `categoryId ` 对应的类别从管理器的数据存储中被移除时,会发出此信号。被移除类别的父类别由 `parentId` 指定。
仅支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
另请参阅 dataChanged()。
[signal] void QPlaceManager::categoryUpdated(const QPlaceCategory &category, const QString &parentId)
如果管理器数据存储中的category 发生修改,则会发出此信号。被修改类别的父类由parentId 指定。
仅支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
另请参阅 dataChanged()。
QList<QPlaceCategory> QPlaceManager::childCategories(const QString &parentId = QString()) const
返回与parentId 对应的分类的所有子分类列表。如果parentId 为空,则返回所有顶级分类。
QStringList QPlaceManager::childCategoryIds(const QString &parentId = QString()) const
返回与parentId 对应的类别的子类别标识符。如果parentId 为空,则返回所有顶级类别标识符。
QPlace QPlaceManager::compatiblePlace(const QPlace &original) const
返回original 地点的已清理或修改版本,该版本适合保存到此管理器中。
修改后的版本中仅包含该管理器支持的地点详细信息。地点 ID 等特定于管理器的数据不会从original 复制过来。
[signal] void QPlaceManager::dataChanged()
如果底层数据存储发生大规模变更,且管理器认为这些变更足够重大,以至于需要客户端重新加载所有数据,则管理器会发出此信号。
如果该信号被发出,则不会再针对相关的更改发出其他信号。
只有支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
[signal] void QPlaceManager::errorOccurred(QPlaceReply *reply, QPlaceReply::Error error, const QString &errorString = QString())
当在处理reply 时检测到错误时,将发出此信号。随后可能会发出QPlaceManager::finished()信号。
该错误将由错误代码error 描述。如果errorString 不为空,则其中将包含面向开发人员(而非最终用户)的错误文本描述。
该信号与QPlaceReply::errorOccurred() 将同时触发。
注意:请 勿在连接到此信号的槽中删除reply 对象。请改用deleteLater()。
[signal] void QPlaceManager::finished(QPlaceReply *reply)
当reply 处理完成时,会发出此信号。
如果 reply->error() 等于QPlaceReply::NoError ,则表示处理已成功完成。
该信号和QPlaceReply::finished()将同时发出。
注意:请 勿在连接到此信号的槽中删除reply 对象。请改用deleteLater()。
QPlaceContentReply *QPlaceManager::getPlaceContent(const QPlaceContentRequest &request) const
根据request 中指定的参数,获取某个地点的内容。
有关用法示例,请参阅“获取富内容”。
QPlaceDetailsReply *QPlaceManager::getPlaceDetails(const QString &placeId) const
获取与给定的placeId 对应的地点详情。
有关使用示例,请参阅“获取地点详情”。
QPlaceReply *QPlaceManager::initializeCategories()
初始化管理器的分类。
有关用法示例,请参阅“使用类别”。
QList<QLocale> QPlaceManager::locales() const
返回一个首选区域设置的列表。这些区域设置将作为提示,告知管理器应以何种语言、地区和类别返回详细信息。
如果无法满足第一个指定的区域设置,管理器将退而采用下一个,依此类推。某些管理器后端可能不支持严格定义的区域设置集合。 举个任意的例子:法国的某些地区可能提供法语和英语本地化版本,而美国的某些地区可能仅提供英语本地化版本。在此示例中,支持的语言环境集取决于搜索位置。
如果管理器无法满足任何首选区域设置,则会回退到使用后端特有的支持语言。
不同提供商对区域设置的支持可能有所不同。对于支持区域设置的提供商,默认情况下,全局默认区域设置被设为管理器的唯一区域设置。
对于不支持语言环境的经理,语言环境列表始终为空。
另请参阅 setLocales()。
QString QPlaceManager::managerName() const
返回管理器的名称
int QPlaceManager::managerVersion() const
返回管理器版本。
QPlaceMatchReply *QPlaceManager::matchingPlaces(const QPlaceMatchRequest &request) const
返回一个响应,其中包含与request 中指定的地点相对应/匹配的地点列表。请求中指定的地点来自另一个管理员。
QString QPlaceManager::parentCategoryId(const QString &categoryId) const
返回与categoryId 对应的分类的父分类标识符。
[signal] void QPlaceManager::placeAdded(const QString &placeId)
当某个地点被添加到管理器引擎的数据存储中时,会触发此信号。具体添加的地点由placeId 指定。
仅支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
另请参阅 dataChanged()。
[signal] void QPlaceManager::placeRemoved(const QString &placeId)
如果某个位置已被从管理器的数据存储中移除,则会发出此信号。被移除的具体位置由placeId 指定。
仅支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
另请参阅 dataChanged()。
[signal] void QPlaceManager::placeUpdated(const QString &placeId)
如果管理器数据存储中的某个位置已被修改,则会触发此信号。具体被修改的位置由placeId 指定。
仅支持 QPlaceManager::NotificationsFeature 的管理器才会发出此信号。
另请参阅 dataChanged()。
QPlaceIdReply *QPlaceManager::removeCategory(const QString &categoryId)
从管理器中删除与categoryId 对应的分类。
有关用法示例,请参阅“删除分类”。
QPlaceIdReply *QPlaceManager::removePlace(const QString &placeId)
从管理器中移除与placeId 对应的地点。
有关用法示例,请参阅“删除地点(cpp)”。
QPlaceIdReply *QPlaceManager::saveCategory(const QPlaceCategory &category, const QString &parentId = QString())
保存一个category ,该分类是parentId 所指定的分类的子分类。若parentId 为空,则category 将作为顶级分类保存。
有关用法示例,请参阅“保存分类”。
QPlaceIdReply *QPlaceManager::savePlace(const QPlace &place)
保存指定的place 。
有关用法示例,请参阅《保存位置 cpp》。
QPlaceSearchReply *QPlaceManager::search(const QPlaceSearchRequest &request) const
根据request 中指定的参数搜索地点。
请参阅Discovery/Search以了解使用示例。
QPlaceSearchSuggestionReply *QPlaceManager::searchSuggestions(const QPlaceSearchRequest &request) const
根据request 中指定的参数,请求一组搜索词建议。request 中可以包含不完整的搜索词,以及其他数据(例如搜索区域),用于缩小相关结果的范围。
有关用法示例,请参阅“搜索建议”。
void QPlaceManager::setLocale(const QLocale &locale)
一项便捷功能,可将管理员的首选语言环境列表设置为单一的locale 。
void QPlaceManager::setLocales(const QList<QLocale> &locales)
设置首选的locales 列表。
另请参阅 locales()。
© 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.