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
stringbuilder.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
<
QString
>
5
6
//! [0]
7
// Required for using the '_L1' string literal.
8
using
namespace
Qt::StringLiterals;
9
// ...
10
11
QString
foo
;
12
QString
type
=
"long"
;
13
14
foo
=
"vector<"_L1
+ type +
">::iterator"_L1
;
15
16
if
(foo.startsWith(
"("
+ type +
") 0x"
))
17
...
18
//! [0]
19
20
//! [5]
21
#
include
<
QStringBuilder
>
22
23
QString hello(
"hello"
);
24
QStringView
el
= QStringView{ hello }.sliced(2, 3);
25
QString
message
= hello % el %
"world"_L1
% QChar(
'!'
);
26
//! [5]
27
28
//! [6]
29
QString
str
(
"QStringBuilder"
);
30
31
// "s" type is deduced as QStringBuilder<...>
32
auto
s
=
"Like hot glue, "
% str %
" concatenates strings"
;
33
34
// Similarly the return type of this lambda is deduced as QStringBuilder<...>
35
auto
concatenateStr
= []() {
36
return
"Like hot glue, "
% str %
" concatenates strings"
;
37
};
38
//! [6]
39
40
//! [7]
41
QString
s
=
"Like hot glue, "
% str %
" concatenates strings"
;
42
43
// With a lambda, specify a trailing return type:
44
auto
concatenateStr = []() -> QString {
45
return
"Like hot glue, "
% str %
" concatenates strings"
;
46
};
47
//! [7]
s
auto s
[6]
Definition
stringbuilder.cpp:32
str
QString str("QStringBuilder")
[5]
el
QStringView el
Definition
stringbuilder.cpp:24
foo
QString foo
[14]
Definition
stringbuilder.cpp:11
type
QString type
Definition
stringbuilder.cpp:12
message
QString message
Definition
stringbuilder.cpp:25
concatenateStr
auto concatenateStr
Definition
stringbuilder.cpp:35
qtbase
src
corelib
doc
snippets
qstring
stringbuilder.cpp
Generated on
for Qt by
1.16.1