PlaceSearchSuggestionModel QML Type

提供对搜索词建议的访问。更多

Import Statement: import QtLocation 6.9
Since: QtLocation 5.5

属性

方法

详细说明

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

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

offsetlimit 属性可用于访问分页建议。设置offsetlimit 属性后,将返回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 }
}

另请参阅 PlaceSearchModelQPlaceManager

属性文档

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()

根据提供的查询参数更新模型。模型将由部分searchTermsearchArea 的搜索建议列表填充。如果plugin 支持,则可指定其他参数,如limitoffsetupdate() 将参数集提交给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


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