1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui>
|
---|
43 | #include <iostream>
|
---|
44 | using namespace std;
|
---|
45 |
|
---|
46 | class Widget : public QWidget
|
---|
47 | {
|
---|
48 | public:
|
---|
49 | Widget(QWidget *parent = 0);
|
---|
50 | };
|
---|
51 |
|
---|
52 | Widget::Widget(QWidget *parent)
|
---|
53 | : QWidget(parent)
|
---|
54 | {
|
---|
55 | //! [0]
|
---|
56 | QStringList fonts;
|
---|
57 | fonts << "Arial" << "Helvetica" << "Times" << "Courier";
|
---|
58 | //! [0]
|
---|
59 |
|
---|
60 | //! [1]
|
---|
61 | for (int i = 0; i < fonts.size(); ++i)
|
---|
62 | cout << fonts.at(i).toLocal8Bit().constData() << endl;
|
---|
63 | //! [1]
|
---|
64 |
|
---|
65 | //! [2]
|
---|
66 | QStringListIterator javaStyleIterator(fonts);
|
---|
67 | while (javaStyleIterator.hasNext())
|
---|
68 | cout << javaStyleIterator.next().toLocal8Bit().constData() << endl;
|
---|
69 | //! [2]
|
---|
70 |
|
---|
71 | //! [3]
|
---|
72 | QStringList::const_iterator constIterator;
|
---|
73 | for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd();
|
---|
74 | ++constIterator)
|
---|
75 | cout << (*constIterator).toLocal8Bit().constData() << endl;
|
---|
76 | //! [3]
|
---|
77 |
|
---|
78 | //! [4]
|
---|
79 | QString str = fonts.join(",");
|
---|
80 | // str == "Arial,Helvetica,Times,Courier"
|
---|
81 | //! [4]
|
---|
82 |
|
---|
83 | //! [5] //! [6]
|
---|
84 | QStringList list;
|
---|
85 | //! [5]
|
---|
86 | list = str.split(",");
|
---|
87 | // list: ["Arial", "Helvetica", "Times", "Courier"]
|
---|
88 | //! [6]
|
---|
89 |
|
---|
90 | //! [7]
|
---|
91 | QStringList monospacedFonts = fonts.filter(QRegExp("Courier|Fixed"));
|
---|
92 | //! [7]
|
---|
93 |
|
---|
94 | //! [8]
|
---|
95 | QStringList files;
|
---|
96 | files << "$QTDIR/src/moc/moc.y"
|
---|
97 | << "$QTDIR/src/moc/moc.l"
|
---|
98 | << "$QTDIR/include/qconfig.h";
|
---|
99 |
|
---|
100 | files.replaceInStrings("$QTDIR", "/usr/lib/qt");
|
---|
101 | // files: [ "/usr/lib/qt/src/moc/moc.y", ...]
|
---|
102 | //! [8]
|
---|
103 |
|
---|
104 | QString str1, str2, str3;
|
---|
105 | //! [9]
|
---|
106 | QStringList longerList = (QStringList() << str1 << str2 << str3);
|
---|
107 | //! [9]
|
---|
108 |
|
---|
109 | list.clear();
|
---|
110 | //! [10]
|
---|
111 | list << "Bill Murray" << "John Doe" << "Bill Clinton";
|
---|
112 |
|
---|
113 | //! [11]
|
---|
114 | QStringList result;
|
---|
115 | //! [11]
|
---|
116 | result = list.filter("Bill");
|
---|
117 | // result: ["Bill Murray", "Bill Clinton"]
|
---|
118 | //! [10]
|
---|
119 |
|
---|
120 | result.clear();
|
---|
121 | //! [12]
|
---|
122 | foreach (QString str, list) {
|
---|
123 | if (str.contains("Bill"))
|
---|
124 | result += str;
|
---|
125 | }
|
---|
126 | //! [12]
|
---|
127 |
|
---|
128 | list.clear();
|
---|
129 | //! [13]
|
---|
130 | list << "alpha" << "beta" << "gamma" << "epsilon";
|
---|
131 | list.replaceInStrings("a", "o");
|
---|
132 | // list == ["olpho", "beto", "gommo", "epsilon"]
|
---|
133 | //! [13]
|
---|
134 |
|
---|
135 | list.clear();
|
---|
136 | //! [14]
|
---|
137 | list << "alpha" << "beta" << "gamma" << "epsilon";
|
---|
138 | list.replaceInStrings(QRegExp("^a"), "o");
|
---|
139 | // list == ["olpha", "beta", "gamma", "epsilon"]
|
---|
140 | //! [14]
|
---|
141 |
|
---|
142 | list.clear();
|
---|
143 | //! [15]
|
---|
144 | list << "Bill Clinton" << "Murray, Bill";
|
---|
145 | list.replaceInStrings(QRegExp("^(.*), (.*)$"), "\\2 \\1");
|
---|
146 | // list == ["Bill Clinton", "Bill Murray"]
|
---|
147 | //! [15]
|
---|
148 | }
|
---|
149 |
|
---|
150 | int main(int argc, char *argv[])
|
---|
151 | {
|
---|
152 | QApplication app(argc, argv);
|
---|
153 | Widget widget;
|
---|
154 | widget.show();
|
---|
155 | return app.exec();
|
---|
156 | }
|
---|