Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
doc_src_qvarlengtharray.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
4
#
include
<
QVarLengthArray
>
5
6
#
if
0
7
//! [0]
8
int
myfunc_wrong(
int
n)
9
{
10
int
table[n + 1];
// WRONG
11
//...
12
return
table[n];
13
}
14
//! [0]
15
#
endif
16
17
//! [1]
18
int
myfunc_correct
(
int
n)
19
{
20
int
*table =
new
int
[n + 1];
21
//...
22
int
ret = table[n];
23
delete
[] table;
24
return
ret;
25
}
26
//! [1]
27
28
29
//! [2]
30
int
myfunc_q
(
int
n)
31
{
32
QVarLengthArray<
int
, 1024> array(n + 1);
33
//...
34
return
array[n];
35
}
36
//! [2]
37
38
39
void
example
()
40
{
41
//! [3]
42
QVarLengthArray<
int
> array(10);
43
int
*data = array.data();
44
for
(
int
i = 0; i < 10; ++i)
45
data[i] = 2 * i;
46
//! [3]
47
}
example
void example()
[5]
Definition
doc_src_groups.cpp:7
myfunc_q
int myfunc_q(int n)
[1]
Definition
doc_src_qvarlengtharray.cpp:30
myfunc_correct
int myfunc_correct(int n)
[1]
Definition
doc_src_qvarlengtharray.cpp:18
qtbase
src
corelib
doc
snippets
code
doc_src_qvarlengtharray.cpp
Generated on
for Qt by
1.14.0