Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
src_corelib_tools_qlist.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
5QList<int> integerList;
6QList<QString> stringList;
8
9
11QList<QString> list(200);
13
14
16QList<QString> list(200, "Pass");
18
19
21if (list[0] == "Liz")
22 list[0] = "Elizabeth";
24
25
27for (qsizetype i = 0; i < list.size(); ++i) {
28 if (list.at(i) == "Alfonso")
29 cout << "Found Alfonso at position " << i << endl;
30}
32
33
35qsizetype i = list.indexOf("Harumi");
36if (i != -1)
37 cout << "First occurrence of Harumi is at position " << i << endl;
39
40
42QList<int> list(10);
43int *data = list.data();
44for (qsizetype i = 0; i < 10; ++i)
45 data[i] = 2 * i;
47
48
50QList<QString> list;
51list.append("one");
52list.append("two");
53QString three = "three";
55// list: ["one", "two", "three"]
56// three: "three"
58
59
61QList<QString> list;
62list.append("one");
63list.append("two");
64QString three = "three";
65list.append(std::move(three));
66// list: ["one", "two", "three"]
67// three: ""
69
70
72QList<QString> list{"a", "ccc"};
73list.emplace(1, 2, 'b');
74// list: ["a", "bb", "ccc"]
76
77
79QList<QString> list{"one", "two"};
82// list: ["one", "two", "aaa"]
84
85
87QList<QString> list;
89ref = "one";
90// list: ["one"]
92
93
95QList<QString> list;
98list.prepend("three");
99// list: ["three", "two", "one"]
101
102
104QList<QString> list = {"alpha", "beta", "delta"};
105list.insert(2, "gamma");
106// list: ["alpha", "beta", "gamma", "delta"]
108
109
111QList<double> list = {2.718, 1.442, 0.4342};
112list.insert(1, 3, 9.9);
113// list: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342]
115
116
118QList<QString> list(3);
119list.fill("Yes");
120// list: ["Yes", "Yes", "Yes"]
121
122list.fill("oh", 5);
123// list: ["oh", "oh", "oh", "oh", "oh"]
125
126
128QList<QString> list{"A", "B", "C", "B", "A"};
129list.indexOf("B"); // returns 1
130list.indexOf("B", 1); // returns 1
131list.indexOf("B", 2); // returns 3
132list.indexOf("X"); // returns -1
134
135
137QList<QString> list = {"A", "B", "C", "B", "A"};
138list.lastIndexOf("B"); // returns 3
139list.lastIndexOf("B", 3); // returns 3
140list.lastIndexOf("B", 2); // returns 1
141list.lastIndexOf("X"); // returns -1
qsizetype size() const noexcept
Definition qlist.h:397
QList< T > & fill(parameter_type t, qsizetype size=-1)
Definition qlist.h:903
iterator insert(qsizetype i, parameter_type t)
Definition qlist.h:488
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
reference emplaceBack(Args &&... args)
Definition qlist.h:882
void prepend(rvalue_ref t)
Definition qlist.h:473
iterator emplace(const_iterator before, Args &&... args)
Definition qlist.h:530
pointer data()
Definition qlist.h:431
void append(parameter_type t)
Definition qlist.h:458
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint ref
ptrdiff_t qsizetype
Definition qtypes.h:165
qsizetype i
[4]
QString three
qDebug()<< list
[1]
QList< QString > stringList
QList< QString > list(200)
[0]
QList< int > integerList
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962
qsizetype lastIndexOf(const AT &t, qsizetype from=-1) const noexcept
Definition qlist.h:969