PlaceSearchSuggestionModel QML Type
提供对搜索词建议的访问。更多
Import Statement: | import QtLocation 6.9 |
Since: | QtLocation 5.5 |
属性
- limit : int
- offset : int
- plugin : Plugin
- searchArea : geoshape
- searchTerm : string
- status : enum
- suggestions : stringlist
方法
- void cancel()
- string errorString()
- void reset()
- void update()
详细说明
当用户输入搜索词时,PlaceSearchSuggestionModel 可用于提供搜索词建议。该模型的属性应与用于执行实际搜索查询的PlaceSearchModel 的属性相匹配,以确保搜索建议结果的相关性。
访问该模型提供的数据有两种方法,一种是通过suggestions 属性,另一种是通过视图和委托。后者是首选方法。
offset 和limit 属性可用于访问分页建议。设置offset 和limit 属性后,将返回offset 和 (offset +limit - 1) 之间的建议。不同插件对分页的支持可能有所不同。
该模型返回以下角色的数据:
角色 | 类型 | 描述 |
---|---|---|
建议 | 字符串 | 建议的搜索词。 |
下面的示例展示了如何使用 PlaceSearchSuggestionModel 从部分搜索词中获取建议搜索词。searchArea 设置为与使用PlaceSearchModel 执行实际地点搜索时使用的匹配。
import QtQuick import QtPositioning import QtLocation PlaceSearchSuggestionModel { id: suggestionModel plugin: myPlugin // Brisbane searchArea: QtPositioning.circle(QtPositioning.coordinate(-27.46778, 153.02778)) onSearchTermChanged: update() } ListView { model: suggestionModel delegate: Text { text: suggestion } }
另请参阅 PlaceSearchModel 和QPlaceManager 。
属性文档
searchArea : geoshape |
searchTerm : string |
该属性包含查询中使用的部分搜索词。
status : enum |
该属性表示模型的状态。它可以是
PlaceSearchSuggestionModel.Null | 未执行搜索查询。模型为空。 |
PlaceSearchSuggestionModel.Ready | 搜索查询已完成,结果可用。 |
PlaceSearchSuggestionModel.Loading | 正在执行搜索查询。 |
PlaceSearchSuggestionModel.错误 | 执行上一个搜索查询时发生错误。 |
suggestions : stringlist |
该属性包含模型当前拥有的预测搜索词列表。
方法文档
void cancel() |
立即取消正在进行的搜索建议操作,并将模型状态设置为PlaceSearchSuggestionModel.Ready。模型会保留操作开始前的任何搜索建议。
如果操作未在进行中,调用 cancel() 将不起作用。
string errorString() |
此只读属性保存最新搜索建议模型错误的文本展示。如果没有发生错误,或者模型已被清除,则返回空字符串。
如果发生的错误没有相关的文字表述,也会返回空字符串。
void reset() |
重置模型。所有搜索建议都会被清除,任何未执行的请求都会被中止,可能出现的错误也会被清除。模型状态将设置为PlaceSearchSuggestionModel.Null。
void update() |
根据提供的查询参数更新模型。模型将由部分searchTerm 和searchArea 的搜索建议列表填充。如果plugin 支持,则可指定其他参数,如limit 和offset 。update()
将参数集提交给plugin 处理。
当模型更新时,模型的status 会被设置为PlaceSearchSuggestionModel.Loading
。如果模型更新成功,status 会被设置为PlaceSearchSuggestionModel.Ready
,如果更新不成功,status 会被设置为PlaceSearchSuggestionModel.Error
,模型也会被清除。
本例展示了模型的使用
PlaceSeachSuggestionModel { id: model plugin: backendPlugin searchArea: QtPositioning.circle(QtPositioning.coordinate(10, 10)) ... } MouseArea { ... onClicked: { model.searchTerm = "piz" model.searchArea.center.latitude = -27.5; model.searchArea.cetner.longitude = 153; model.update(); } }
更详细的示例可在Places (QML)示例中找到。
© 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.