ContactDetails QML Type (Uncreatable)
ContactDetails 类型用于存储Place 的联系信息。更多内容...
| Import Statement: | import QtLocation 6.12 |
| Since: | QtLocation 5.5 |
注意:这是一个不可创建的类型。无法在 QML 中对其进行实例化。
方法
- variant keys()
详细说明
ContactDetails 类型是一个由contactDetail 对象组成的映射。要访问映射中的联系人详细信息,请使用keys() 方法获取映射中存储的键列表,然后使用[] 运算符访问contactDetail 项。
API 中定义了以下键。Plugin 的实现可以自由定义其他键。
- phone
- fax
- website
ContactDetails 实例仅在Places 的上下文中使用。无法直接创建 ContactDetails 实例,也无法将 ContactDetails 实例重新分配给Places 。对 ContactDetails 的修改只能通过 JavaScript 实现。
示例
以下示例演示了如何访问所有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()
返回一个数组,其中包含当前存储在映射中的联系人详细信息键。
© 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.