blob: 7b71e30ba51ec5fa6546f1bbd21a829fe31f328e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick 2.0
import test.ListPropertyTest
Rectangle {
width: 360
height: 360
Person {
id: person
friends: [
Person{
name: "Alice"
},
Person{
name: "Bob"
},
Person{
name: "Charlie"
}
]
}
Person{
id: david
name: "David"
}
Component.onCompleted: {
// Access the length of the list
console.log("List length: " + person.friends.length);
// Access the first element of the list
console.log("First element: " + person.friends[0].name);
// Remove the last item of the list
console.log("Removing last item: " + person.friends.pop().name);
// Repalce the last item of the list
console.log("Replacing last item: " + person.friends[person.friends.length - 1].name);
person.friends[person.friends.length - 1] = david;
console.log("Replaced last item: " + person.friends[person.friends.length - 1].name);
// Clear the list
person.friends = [];
console.log("List length after clearing: " + person.friends.length);
}
}
|