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 }.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]
auto s
[6]
QString str("QStringBuilder")
[5]
QStringView el
QString foo
[14]
QString type
QString message
auto concatenateStr