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.
8using namespace Qt::StringLiterals;
9// ...
10
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 }.mid(2, 3);
26 QString message = hello % el % world % QChar('!');
27//! [5]
28
29//! [6]
30 QString str("QStringBuilder");
31
32 // "s" type is deduced as QStringBuilder<...>
33 auto s = "Like hot glue, " % str % " concatenates strings";
34
35 // Similarly the return type of this lambda is deduced as QStringBuilder<...>
36 auto concatenateStr = []() {
37 return "Like hot glue, " % str % " concatenates strings";
38 };
39//! [6]
40
41//! [7]
42 QString s = "Like hot glue, " % str % " concatenates strings";
43
44 // With a lambda, specify a trailing return type:
45 auto concatenateStr = []() -> QString {
46 return "Like hot glue, " % str % " concatenates strings";
47 };
48//! [7]
auto s
[6]
QString str("QStringBuilder")
[5]
QStringView el
QString foo
[14]
QString type
QLatin1StringView world("world")
QString message
auto concatenateStr