ContactDetails QML Type
ContactDetails 类型保存Place... 更多...
Import Statement: | import QtLocation 6.9 |
Since: | QtLocation 5.5 |
方法
- variant keys()
详细描述
ContactDetails 类型是contactDetail 对象的映射。要访问映射中的联系人详细信息,请使用keys() 方法获取存储在映射中的键列表,然后使用[]
操作符访问contactDetail 项目。
以下键值已在 API 中定义。Plugin 实现可自由定义其他键值。
- 电话
- 传真
- 电子邮件
- 网站
ContactDetails 实例只能在Places 的上下文中使用。无法直接创建 ContactDetails 实例,也无法将 ContactDetails 实例重新分配给Places 。只能通过 Javascript 来修改 ContactDetails。
示例
下面的示例显示了如何访问所有contact details 并打印到控制台:
import QtPositioning import QtLocation function printContactDetails(contactDetails) { var keys = contactDetails.keys(); for (var i = 0; i < keys.length; ++i) { var contactList = contactDetails[keys[i]]; for (var j = 0; j < contactList.length; ++j) { console.log(contactList[j].label + ": " + contactList[j].value); } } }
返回的联系人详细信息列表是一个对象列表,因此可以直接用作数据模型。例如,下面的示例演示了如何在列表视图中显示联系人电话号码列表:
import QtQuick import QtPositioning import QtLocation ListView { model: place.contactDetails.phone; delegate: Text { text: modelData.label + ": " + modelData.value } }
下面的示例演示了如何用 JavaScript 将单个电话号码分配给一个地点:
function writeSingle() { var phoneNumber = Qt.createQmlObject('import QtLocation; ContactDetail {}', place); phoneNumber.label = "Phone"; phoneNumber.value = "555-5555" place.contactDetails.phone = phoneNumber; }
以下示例演示了如何在 JavaScript 中为一个地点分配多个电话号码:
function writeMultiple() { var bob = Qt.createQmlObject('import QtLocation; ContactDetail {}', place); bob.label = "Bob"; bob.value = "555-5555" var alice = Qt.createQmlObject('import QtLocation; ContactDetail {}', place); alice.label = "Alice"; alice.value = "555-8745" var numbers = new Array(); numbers.push(bob); numbers.push(alice); place.contactDetails.phone = numbers; }
方法文档
variant keys() |
返回当前存储在地图中的联系人详细信息键数组。
© 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.