1QStringList(3qt)                                              QStringList(3qt)
2
3
4

NAME

6       QStringList - List of strings
7

SYNOPSIS

9       All the functions in this class are reentrant when Qt is built with
10       thread support.</p>
11
12       #include <qstringlist.h>
13
14       Inherits QValueList<QString>.
15
16   Public Members
17       QStringList ()
18       QStringList ( const QStringList & l )
19       QStringList ( const QValueList<QString> & l )
20       QStringList ( const QString & i )
21       QStringList ( const char * i )
22       void sort ()
23       QString join ( const QString & sep ) const
24       QStringList grep ( const QString & str, bool cs = TRUE ) const
25       QStringList grep ( const QRegExp & rx ) const
26       QStringList & gres ( const QString & before, const QString & after,
27           bool cs = TRUE )
28       QStringList & gres ( const QRegExp & rx, const QString & after )
29
30   Static Public Members
31       QStringList fromStrList ( const QStrList & ascii )
32       QStringList split ( const QString & sep, const QString & str, bool
33           allowEmptyEntries = FALSE )
34       QStringList split ( const QChar & sep, const QString & str, bool
35           allowEmptyEntries = FALSE )
36       QStringList split ( const QRegExp & sep, const QString & str, bool
37           allowEmptyEntries = FALSE )
38

DESCRIPTION

40       The QStringList class provides a list of strings.
41
42       It is used to store and manipulate strings that logically belong
43       together. Essentially QStringList is a QValueList of QString objects.
44       Unlike QStrList, which stores pointers to characters, QStringList holds
45       real QString objects. It is the class of choice whenever you work with
46       Unicode strings. QStringList is part of the Qt Template Library.
47
48       Like QString itself, QStringList objects are implicitly shared, so
49       passing them around as value-parameters is both fast and safe.
50
51       Strings can be added to a list using append(), operator+=() or
52       operator<<(), e.g.
53
54           QStringList fonts;
55           fonts.append( "Times" );
56           fonts += "Courier";
57           fonts += "Courier New";
58           fonts << "Helvetica [Cronyx]" << "Helvetica [Adobe]";
59
60       String lists have an iterator, QStringList::Iterator(), e.g.
61
62           for ( QStringList::Iterator it = fonts.begin(); it != fonts.end(); ++it ) {
63               cout << *it << ":";
64           }
65           cout << endl;
66           // Output:
67           //  Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:
68
69       Many Qt functions return string lists by value; to iterate over these
70       you should make a copy and iterate over the copy.
71
72       You can concatenate all the strings in a string list into a single
73       string (with an optional separator) using join(), e.g.
74
75           QString allFonts = fonts.join( ", " );
76           cout << allFonts << endl;
77           // Output:
78           //  Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe]
79
80       You can sort the list with sort(), and extract a new list which
81       contains only those strings which contain a particular substring (or
82       match a particular regular expression) using the grep() functions, e.g.
83
84           fonts.sort();
85           cout << fonts.join( ", " ) << endl;
86           // Output:
87           //  Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times
88           QStringList helveticas = fonts.grep( "Helvetica" );
89           cout << helveticas.join( ", " ) << endl;
90           // Output:
91           //  Helvetica [Adobe], Helvetica [Cronyx]
92
93       Existing strings can be split into string lists with character, string
94       or regular expression separators, e.g.
95
96           QString s = "Red\tGreen\tBlue";
97           QStringList colors = QStringList::split( "\t", s );
98           cout << colors.join( ", " ) << endl;
99           // Output:
100           //  Red, Green, Blue
101
102       See also Implicitly and Explicitly Shared Classes, Text Related
103       Classes, and Non-GUI Classes.
104

MEMBER FUNCTION DOCUMENTATION

QStringList::QStringList ()

107       Creates an empty string list.
108

QStringList::QStringList ( const QStringList & l )

110       Creates a copy of the list l. This function is very fast because
111       QStringList is implicitly shared. In most situations this acts like a
112       deep copy, for example, if this list or the original one or some other
113       list referencing the same shared data is modified, the modifying list
114       first makes a copy, i.e. copy-on-write. In a threaded environment you
115       may require a real deep copy
116

QStringList::QStringList ( const QValueList<QString> & l )

118       Constructs a new string list that is a copy of l.
119

QStringList::QStringList ( const QString & i )

121       Constructs a string list consisting of the single string i. Longer
122       lists are easily created as follows:
123
124           QStringList items;
125           items << "Buy" << "Sell" << "Update" << "Value";
126

QStringList::QStringList ( const char * i )

128       Constructs a string list consisting of the single Latin-1 string i.
129

QStringList QStringList::fromStrList ( const QStrList & ascii ) [static]

131       Converts from an ASCII-QStrList ascii to a QStringList (Unicode).
132

QStringList QStringList::grep ( const QString & str, bool cs = TRUE ) const

134       Returns a list of all the strings containing the substring str.
135
136       If cs is TRUE, the grep is done case-sensitively; otherwise case is
137       ignored.
138
139           QStringList list;
140           list << "Bill Gates" << "John Doe" << "Bill Clinton";
141           list = list.grep( "Bill" );
142           // list == ["Bill Gates", "Bill Clinton"]
143
144       See also QString::find().
145

QStringList QStringList::grep ( const QRegExp & rx ) const

147       This is an overloaded member function, provided for convenience. It
148       behaves essentially like the above function.
149
150       Returns a list of all the strings that match the regular expression rx.
151
152       See also QString::find().
153

QStringList & QStringList::gres ( const QString & before, const QString &

155       after, bool cs = TRUE )
156       Replaces every occurrence of the string before in the strings that
157       constitute the string list with the string after. Returns a reference
158       to the string list.
159
160       If cs is TRUE, the search is case sensitive; otherwise the search is
161       case insensitive.
162
163       Example:
164
165           QStringList list;
166           list << "alpha" << "beta" << "gamma" << "epsilon";
167           list.gres( "a", "o" );
168           // list == ["olpho", "beto", "gommo", "epsilon"]
169
170       See also QString::replace().
171

QStringList & QStringList::gres ( const QRegExp & rx, const QString & after )

173       This is an overloaded member function, provided for convenience. It
174       behaves essentially like the above function.
175
176       Replaces every occurrence of the regexp rx in the string with after.
177       Returns a reference to the string list.
178
179       Example:
180
181           QStringList list;
182           list << "alpha" << "beta" << "gamma" << "epsilon";
183           list.gres( QRegExp("^a"), "o" );
184           // list == ["olpha", "beta", "gamma", "epsilon"]
185
186       For regexps containing capturing parentheses, occurrences of &#92;1,
187       &#92;2, ..., in after are replaced with rx.cap(1), cap(2), ...
188
189       Example:
190
191           QStringList list;
192           list << "Bill Clinton" << "Gates, Bill";
193           list.gres( QRegExp("^(.*), (.*)$"), "\\2 \\1" );
194           // list == ["Bill Clinton", "Bill Gates"]
195
196       See also QString::replace().
197

QString QStringList::join ( const QString & sep ) const

199       Joins the string list into a single string with each element separated
200       by the string sep (which can be empty).
201
202       See also split().
203
204       Examples:
205

void QStringList::sort ()

207       Sorts the list of strings in ascending case-sensitive order.
208
209       Sorting is very fast. It uses the Qt Template Library's efficient
210       HeapSort implementation that has a time complexity of O(n*log n).
211
212       If you want to sort your strings in an arbitrary order consider using a
213       QMap. For example you could use a QMap<QString,QString> to create a
214       case-insensitive ordering (e.g. mapping the lowercase text to the
215       text), or a QMap<int,QString> to sort the strings by some integer
216       index, etc.
217
218       Example: themes/themes.cpp.
219

QStringList QStringList::split ( const QRegExp & sep, const QString & str,

221       bool allowEmptyEntries = FALSE ) [static]
222       Splits the string str into strings wherever the regular expression sep
223       occurs, and returns the list of those strings.
224
225       If allowEmptyEntries is TRUE, a null string is inserted in the list
226       wherever the separator matches twice without intervening text.
227
228       For example, if you split the string "a,,b,c" on commas, split()
229       returns the three-item list "a", "b", "c" if allowEmptyEntries is FALSE
230       (the default), and the four-item list "a", "", "b", "c" if
231       allowEmptyEntries is TRUE.
232
233       If sep does not match anywhere in str, split() returns a single element
234       list with the element containing the single string str.
235
236       See also join() and QString::section().
237
238       Examples:
239

QStringList QStringList::split ( const QString & sep, const QString & str,

241       bool allowEmptyEntries = FALSE ) [static]
242       This is an overloaded member function, provided for convenience. It
243       behaves essentially like the above function.
244
245       This version of the function uses a QString as separator, rather than a
246       regular expression.
247
248       If sep is an empty string, the return value is a list of one-character
249       strings: split( QString( "" ), "four" ) returns the four-item list,
250       "f", "o", "u", "r".
251
252       If allowEmptyEntries is TRUE, a null string is inserted in the list
253       wherever the separator matches twice without intervening text.
254
255       See also join() and QString::section().
256

QStringList QStringList::split ( const QChar & sep, const QString & str, bool

258       allowEmptyEntries = FALSE ) [static]
259       This is an overloaded member function, provided for convenience. It
260       behaves essentially like the above function.
261
262       This version of the function uses a QChar as separator, rather than a
263       regular expression.
264
265       See also join() and QString::section().
266
267

SEE ALSO

269       http://doc.trolltech.com/qstringlist.html
270       http://www.trolltech.com/faq/tech.html
271
273       Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
274       license file included in the distribution for a complete license
275       statement.
276

AUTHOR

278       Generated automatically from the source code.
279

BUGS

281       If you find a bug in Qt, please report it as described in
282       http://doc.trolltech.com/bughowto.html.  Good bug reports help us to
283       help you. Thank you.
284
285       The definitive Qt documentation is provided in HTML format; it is
286       located at $QTDIR/doc/html and can be read using Qt Assistant or with a
287       web browser. This man page is provided as a convenience for those users
288       who prefer man pages, although this format is not officially supported
289       by Trolltech.
290
291       If you find errors in this manual page, please report them to qt-
292       bugs@trolltech.com.  Please include the name of the manual page
293       (qstringlist.3qt) and the Qt version (3.3.8).
294
295
296
297Trolltech AS                    2 February 2007               QStringList(3qt)
Impressum