![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QStringList class provides a list of strings. More...
#include <qstringlist.h>
Inherits QValueList<QString>.
It is used to store and manipulate strings that logically belong together. Basically QStringList is a QValueList of QString objects. As opposed to QStrList, which stores pointers to characters, QStringList deals with real QString objects. It is the class of choice whenever you work with Unicode strings. QStringList is part of the Qt Template Library.
Like QString itself, QStringList objects are implicitly shared. Passing them around as value-parameters is both fast and safe.
There are several approaches to add strings to a string list:
QStringList substitutes; substitutes.append( "Times" ); substitutes += "Mincho", substitutes << "Arabic Newspaper" << "crox";
To successively access the members of a QStringList use the provided Iterator:
QStringList substitutions = QFont::substitutes( font.family() );
QStringList::Iterator i = substitutions.begin(); while ( i != substitutions.end() ){ messageText += "<LI>\"" + (* i) + "\""; i++; }
(Code examples taken from examples/fonts/simple-qfont-demo/viewer.cpp)
Convenience methods such as sort(), split(), join() and grep() make working with QStringLists easy.
Creates a copy of the list l. This function is very fast because QStringList is implicitly shared. However, for the programmer this is the same as a deep copy. If this list or the original one or some other list referencing the same shared data is modified, the modifying list first makes a copy.
Constructs a new string list that is a copy of l.
Constructs a string list consisting of the single string i. Longer lists are easily created as follows:
QStringList comboEntries; comboEntries << "one" << "two" << "three" << "four";
(example code taken from table/small-table-demo/main.cpp)
If cs is TRUE, the grep is done case-sensitively, otherwise not.
Returns a list of all strings containing a substring that matches the regular expression expr.
See also split().
Sorting is very fast. It uses the Qt Template Library's efficient HeapSort implementation that operates in O(n*log n).
If allowEmptyEntries is TRUE, an empty string is inserted in the list wherever the separator matches twice without intervening text.
For example, if you split the string "a,,b,c" on commas, split() returns the three-item list "a", "b", "c" if allowEmptyEntries is FALSE (the default), and the four-item list "a", "", "b", "c" if allowEmptyEntries is TRUE.
If sep does not match anywhere in str, split() returns a list consisting of the single string str.
See also join().
Examples: dirview/dirview.cpp and network/httpd/httpd.cpp.
This version of the function uses a QChar as separator, rather than a full regular expression.
If sep is an empty string, the return value is a list of one-character strings: split( QString( "" ), "mfc" ) returns the three-item list "m", "f", "c".
If allowEmptyEntries is TRUE, an empty string is inserted in the list wherever the separator matches twice without intervening text.
This version of the function uses a QChar as separator, rather than a full regular expression.
See also join().
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta2
|