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
src_corelib_text_qstring.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
6using namespace Qt::StringLiterals;
7
8
9struct Node
10{
11 QString name() const;
12 bool hasAttribute(const QString &name);
13};
14
15void example()
16{
17 {
18 //! [1]
19 // Required for using the '_L1' string literal.
20 using namespace Qt::StringLiterals;
21 // ...
22 QString url = "https://www.unicode.org/"_L1;
23 //! [1]
24 }
25
26 {
27 //! [2]
28 double d = 12.34;
29 QString str = QString("delta: %1").arg(d, 0, 'E', 3);
30 // str == "delta: 1.234E+01"
31 //! [2]
32 }
33
34 QString str;
35
36 {
37 //! [3]
38 if (str == "auto" || str == "extern"
39 || str == "static" || str == "register") {
40 //...
41 }
42 //! [3]
43 }
44
45 {
46 //! [4]
47 if (str == QString("auto") || str == QString("extern")
48 || str == QString("static") || str == QString("register")) {
49 //...
50 }
51 //! [4]
52 }
53
54 {
55 //! [4bis]
56 str.append("Hello ").append("World");
57 //! [4bis]
58 }
59
60 {
61 //! [5]
62 // Required for using the '_L1' string literal.
63 using namespace Qt::StringLiterals;
64 // ...
65 if (str == "auto"_L1
66 || str == "extern"_L1
67 || str == "static"_L1
68 || str == "register"_L1) {
69 //...
70 }
71 //! [5]
72 }
73
74 {
75 //! [7]
76 QString plain = "#include <QtCore>";
77 QString html = plain.toHtmlEscaped();
78 // html == "#include &lt;QtCore&gt;"
79 //! [7]
80 }
81
82 {
83 //! [8]
84 QString str("ab");
85 str.repeated(4); // returns "abababab"
86 //! [8]
87 }
88
89 {
90 Node node;
91 Node attribute;
92
93 //! [9]
94 // hasAttribute takes a QString argument
95 if (node.hasAttribute("http-contents-length")) {
96 //...
97 }
98 //! [9]
99
100 //! [10]
101 if (node.hasAttribute(QStringLiteral(u"http-contents-length"))){
102 //...
103 }
104 //! [10]
105
106 //! [11]
107 if (attribute.name() == "http-contents-length"_L1){
108 //...
109 }
110 //! [11]
111 }
112
113 {
114 QString key;
115 QString value;
116
117 //! [qUtf8Printable]
118 qWarning("%s: %s", qUtf8Printable(key), qUtf8Printable(value));
119 //! [qUtf8Printable]
120
121 //! [qUtf16Printable]
122 qWarning("%ls: %ls", qUtf16Printable(key), qUtf16Printable(value));
123 //! [qUtf16Printable]
124 }
125}
126
127#if __has_include(<QWidget>)
128
129#include <QLabel>
130#include <QWidget>
131
132class LabelExample : public QWidget
133{
134 Q_OBJECT
135 void exampleWithLabel()
136 {
137 //! [6]
138 QLabel *label = new QLabel("MOD"_L1, this);
139 //! [6]
140 }
141};
142#endif
void example()
[5]
#define __has_include(x)
The Node class is the base class for all the nodes in QDoc's parse tree.
bool hasAttribute(const QString &name)
QString name() const
Returns the node's name data member.