RouteModel QML Type
RouteModel 类型用于访问路由。更多内容...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 5.5 |
属性
- autoUpdate : bool
- count : int
- error : enumeration
- errorString : string
- measurementSystem : Locale::MeasurementSystem
- plugin : Plugin
- query : RouteQuery
- status : enumeration
方法
详细说明
RouteModel 类型作为模型/视图组合的一部分,用于从后端提供商中检索地理路线。 路线包括两点之间的驾车路线、包含多个途经点的步行路线,以及其他各种类似的概念。其功能与 QML 中的其他 Model 类型(例如ListModel)非常相似,并可与MapItemView 和ListView 等视图进行交互。
与Map 和GeocodeModel 一样,RouteModel运行所需的所有数据均来自服务插件。该数据存储在plugin 属性中,必须在RouteModel执行任何有效操作之前设置该属性。
设置好插件后,请创建一个包含适当路点和其他设置的RouteQuery ,并设置RouteModel的query 属性。如果启用了autoUpdate ,更新将自动开始。否则,可使用update 方法。默认情况下,autoUpdate 处于禁用状态。
RouteModel 中存储和返回的数据由route 对象组成,以名称为“routeData”的列表形式呈现。有关其结构和内容的更多详细信息,请参阅route 的文档。
使用示例
以下代码片段分为两部分:首先展示对象的声明,其次展示一段使用该对象的简短过程式代码。我们将 routeModel 的autoUpdate 属性设置为 false,并在查询配置完成后调用update ,以避免在查询配置过程中产生无用的额外请求。
Plugin {
id: aPlugin
name: "osm"
}
RouteQuery {
id: aQuery
}
RouteModel {
id: routeModel
plugin: aPlugin
query: aQuery
autoUpdate: false
}{
aQuery.addWaypoint(...)
aQuery.addWaypoint(...)
aQuery.travelModes = ...
routeModel.update()
}属性文档
autoUpdate : bool
该属性控制模型是否会根据其关联的RouteQuery 中的变化自动更新。该属性的默认值为false。
如果将此值设置为“true”,请注意,query 属性中设置的RouteQuery 对象中的任何变化都会触发发送一个新的请求。如果在启用autoUpdate的情况下调整RouteQuery 的许多属性,这可能会产生大量无用的(且随后会被丢弃的)请求。
count : int [read-only]
该属性保存了模型当前拥有的路由数量。除其他用途外,您还可以在通过 QtLocation::RouteModel::get 方法访问路由时使用该值。
error : enumeration [read-only]
此只读属性保存路由请求的最新错误值。
- RouteModelNoError ——未发生错误。
- RouteModel.xml-ph-0000@deepl.internal - 未发生错误。.CommunicationError - 与服务提供商通信时发生错误。
- RouteModel.EngineNotSetError - 模型的插件属性未设置,或者该插件未关联任何路由管理器。
- RouteModel.MissingRequiredParameterError - 未指定必填参数。
- RouteModel.ParseError - 服务提供商的响应格式无法识别。
- RouteModel.UnknownError - 发生了一项无法归入其他任何类别的错误。
- RouteModel.UnknownParameterError - 插件未识别其接收到的某个参数。
- RouteModel.UnsupportedOptionError - 路由提供商不支持所请求的操作。当加载的引擎不支持特定类型的路由请求时,可能会发生这种情况。
errorString : string [read-only]
此只读属性存储最新路由错误的文本描述。如果未发生错误或模型已被重置,则返回空字符串。
如果发生的错误没有相关的文本表示形式,也会返回空字符串。
measurementSystem : Locale::MeasurementSystem
该属性存储计算路线时将使用的度量单位。当plugin 的Plugin::locales 属性发生变化时,该属性也会随之改变。
若要设置此属性,必须在设置完plugin 属性之后进行。
plugin : Plugin
该属性包含提供实际路由服务的插件。请注意,并非所有插件都一定提供路由功能(例如,有些插件可能仅提供地理编码或地图功能)。
在RouteModel 能够执行任何有效操作之前,必须先设置一个有效的插件。
另请参阅 Plugin 。
query : RouteQuery
该属性存储了路线请求的数据。主要数据包括途经点的坐标以及可能的其他偏好设置(如出行方式、路线上需避开的地点等)。
status : enumeration [read-only]
此只读属性保存了模型的当前状态。
- RouteModel.Null - 尚未发出任何路由请求,或者已调用reset 方法。
- RouteModel.Ready - 路由请求已成功完成。
- RouteModel.Loading - 已发出路由请求但尚未完成
- RouteModel.Error - 发生路由错误,详情请参见error 和errorString
方法文档中
void cancel()
取消所有待处理的请求并清除错误。模型状态将设置为RouteModel.Null 或RouteModel.Ready。
route get(int index)
返回位于指定位置index 的路线。使用count 属性检查可用的路线数量。路线从零开始编号,因此可访问的范围为0...(count - 1)。
如果访问超出范围,将返回一个空路由并触发警告。
void reset()
重置模型。所有路由数据将被清除,所有未处理的请求将被中止,并清除可能存在的错误。模型状态将设置为RouteModel.Null。
void update()
指示RouteModel 更新其数据。当autoUpdate 被禁用时,此功能最为有用,可在查询内容发生变化时强制刷新数据。
© 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.