Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
main.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 <QtGui>
5#include <iostream>
6using namespace std;
7
8class Widget : public QWidget
9{
10public:
11 Widget(QWidget *parent = nullptr);
12};
13
15 : QWidget(parent)
16{
18 QStringList fonts = { "Arial", "Helvetica", "Times" };
20
22 fonts << "Courier" << "Verdana";
24
26 QString str = fonts.join(", ");
27 // str == "Arial, Helvetica, Times, Courier"
29
33 list = str.split(',');
34 // list: ["Arial", "Helvetica", "Times", "Courier"]
36
38 QStringList monospacedFonts = fonts.filter(QRegularExpression("Courier|Fixed"));
40
43 files << "$QTDIR/src/moc/moc.y"
44 << "$QTDIR/src/moc/moc.l"
45 << "$QTDIR/include/qconfig.h";
46
47 files.replaceInStrings("$QTDIR", "/usr/lib/qt");
48 // files: [ "/usr/lib/qt/src/moc/moc.y", ...]
50
51 QString str1, str2, str3;
53 QStringList longerList = (QStringList() << str1 << str2 << str3);
55
56 list.clear();
58 list << "Bill Murray" << "John Doe" << "Bill Clinton";
59
63 result = list.filter("Bill");
64 // result: ["Bill Murray", "Bill Clinton"]
66
67 result.clear();
69 for (const auto &str : std::as_const(list)) {
70 if (str.contains("Bill"))
71 result += str;
72 }
74
75 list.clear();
77 list << "alpha" << "beta" << "gamma" << "epsilon";
78 list.replaceInStrings("a", "o");
79 // list == ["olpho", "beto", "gommo", "epsilon"]
81
82 list.clear();
84 list << "alpha" << "beta" << "gamma" << "epsilon";
85 list.replaceInStrings(QRegularExpression("^a"), "o");
86 // list == ["olpha", "beta", "gamma", "epsilon"]
88
89 list.clear();
91 list << "Bill Clinton" << "Murray, Bill";
92 list.replaceInStrings(QRegularExpression("^(.*), (.*)$"), "\\2 \\1");
93 // list == ["Bill Clinton", "Bill Murray"]
95
96 {
98 QStringList veryLongList;
100 QStringList filtered = veryLongList.filter(matcher);
102 }
103}
104
105int main(int argc, char *argv[])
106{
107 QApplication app(argc, argv);
109 widget.show();
110 return app.exec();
111}
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
void clear()
Definition qlist.h:434
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
\inmodule QtCore \reentrant
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QStringList split(const QString &sep, Qt::SplitBehavior behavior=Qt::KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Splits the string into substrings wherever sep occurs, and returns the list of those strings.
Definition qstring.cpp:8218
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition qstring.h:1369
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
Widget(QWidget *parent=nullptr)
QOpenGLWidget * widget
[1]
QString str
[2]
int main()
[0]
QFuture< typename std::decay_t< Sequence >::value_type > filtered(QThreadPool *pool, Sequence &&sequence, KeepFunctor &&keep)
Calls filterFunction once for each item in sequence and returns a new Sequence of kept items.
@ CaseInsensitive
QList< QString > QStringList
Constructs a string list that contains the given string, str.
GLuint64EXT * result
[6]
QList< int > list
[14]
static const auto matcher
[0]
QStringList files
[8]
QApplication app(argc, argv)
[0]