本页内容

PlaceSearchSuggestionModel QML Type

提供搜索词建议功能。更多...

Import Statement: import QtLocation 6.12
Since: QtLocation 5.5

属性

方法

详细说明

PlaceSearchSuggestionModel 可在用户输入搜索词时提供搜索词建议。该模型的属性应与用于执行实际搜索查询的PlaceSearchModel 的属性保持一致,以确保搜索建议结果的相关性。

访问该模型提供的数据有两种方式:通过suggestions 属性,或通过视图和委托。后者是首选方法。

可通过offset 和limit 属性访问分页建议。当设置offset 和limit 属性时,将返回介于offset 和(offset +limit - 1)之间的建议。分页支持情况可能因插件而异。

该模型返回以下角色的数据:

角色类型描述
suggestion字符串建议的搜索词。

以下示例演示了如何使用 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 。

属性文档

limit : int

此属性用于限定将返回的项目数量上限。

另请参阅 offset 。

offset : int

该属性保存模型中第一个项的索引。

另请参阅 limit 。

plugin : Plugin

该属性保存了用于执行搜索的提供程序Plugin 。

searchArea : geoShape

该属性用于指定搜索范围。模型返回的搜索建议结果将与给定的搜索范围相关。

如果此属性设置为geoCircle ,则其radius 属性可以不作设置;在这种情况下,Plugin 将自动选择一个合适的搜索半径。

searchTerm : string

该属性存储查询中使用的部分搜索词。

status : enum [read-only]

该属性保存模型的状态。其取值可以是以下之一:

PlaceSearchSuggestionModel.Null尚未执行任何搜索查询。模型为空。
PlaceSearchSuggestionModel.Ready搜索查询已完成,且结果已可用。
PlaceSearchSuggestionModel.Loading当前正在执行搜索查询。
PlaceSearchSuggestionModel.错误执行上一次搜索查询时发生错误。

suggestions : stringlist [read-only]

该属性包含模型当前拥有的预测搜索词列表。

方法文档

void cancel()

立即取消正在进行的搜索建议操作,并将模型状态设置为PlaceSearchSuggestionModel.Ready。模型将保留该操作启动前的所有搜索建议。

如果当前没有正在进行的操作,调用 cancel() 将不产生任何效果。

另请参阅 update() 和status 。

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)”示例。

另请参阅 cancel() 和status 。

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