Member Function Documentation
QStringList::QStringList ()
Constructs an empty string list.
QStringList::QStringList ( const QString & str )
Constructs a string list that contains the given string, str. Longer lists are easily created like this:
QStringList longerList = (QStringList() << str1 << str2 << str3);
See also append().
QStringList::QStringList ( const QStringList & other )
Constructs a copy of the other string list.
This operation takes constant time because QStringList is implicitly shared, making the process of returning a QStringList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.
See also operator=().
QStringList::QStringList ( const QList<QString> & other )
Constructs a copy of other.
This operation takes constant time, because QStringList is implicitly shared. This makes returning a QStringList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.
See also operator=().
bool QStringList::contains ( const QString & str, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
Returns true if the list contains the string str; otherwise returns false. The search is case insensitive if cs is Qt::CaseInsensitive; the search is case sensitive by default.
See also indexOf(), lastIndexOf(), and QString::contains().
QStringList QStringList::filter ( const QString & str, Qt::CaseSensitivity cs = Qt::CaseSensitive ) const
Returns a list of all the strings containing the substring str.
If cs is Qt::CaseSensitive (the default), the string comparison is case sensitive; otherwise the comparison is case insensitive.
QStringList list;
list << "Bill Murray" << "John Doe" << "Bill Clinton";
QStringList result;
result = list.filter("Bill");
This is equivalent to
QStringList result;
foreach (const QString &str, list) {
if (str.contains("Bill"))
result += str;
}
See also contains().
QStringList QStringList::filter ( const QRegExp & rx ) const
This is an overloaded function.
Returns a list of all the strings that match the regular expression rx.
int QStringList::indexOf ( const QRegExp & rx, int from = 0 ) const
Returns the index position of the first exact match of rx in the list, searching forward from index position from. Returns -1 if no item matched.
By default, this function is case sensitive.
See also lastIndexOf(), contains(), and QRegExp::exactMatch().
int QStringList::indexOf ( const QString & value, int from = 0 ) const
Returns the index position of the first occurrence of value in the list, searching forward from index position from. Returns -1 if no item matched.
See also lastIndexOf(), contains(), and QList::indexOf().
int QStringList::indexOf ( QRegExp & rx, int from = 0 ) const
This function overloads indexOf().
Returns the index position of the first exact match of rx in the list, searching forward from index position from. Returns -1 if no item matched.
By default, this function is case sensitive.
If an item matched, the rx regular expression will contain the matched objects (see QRegExp::matchedLength, QRegExp::cap).
This function was introduced in Qt 4.5.
See also lastIndexOf(), contains(), and QRegExp::exactMatch().
QString QStringList::join ( const QString & separator ) const
Joins all the string list's strings into a single string with each element separated by the given separator (which can be an empty string).
See also QString::split().
int QStringList::lastIndexOf ( const QRegExp & rx, int from = -1 ) const
Returns the index position of the last exact match of rx in the list, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.
By default, this function is case sensitive.
See also indexOf(), contains(), and QRegExp::exactMatch().
int QStringList::lastIndexOf ( const QString & value, int from = -1 ) const
Returns the index position of the last occurrence of value in the list, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.
By default, this function is case sensitive.
See also indexOf() and QList::lastIndexOf().
int QStringList::lastIndexOf ( QRegExp & rx, int from = -1 ) const
This function overloads lastIndexOf().
Returns the index position of the last exact match of rx in the list, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.
By default, this function is case sensitive.
If an item matched, the rx regular expression will contain the matched objects (see QRegExp::matchedLength, QRegExp::cap).
This function was introduced in Qt 4.5.
See also indexOf(), contains(), and QRegExp::exactMatch().
int QStringList::removeDuplicates ()
This function removes duplicate entries from a list. The entries do not have to be sorted. They will retain their original order.
Returns the number of removed entries.
This function was introduced in Qt 4.5.
QStringList & QStringList::replaceInStrings ( const QString & before, const QString & after, Qt::CaseSensitivity cs = Qt::CaseSensitive )
Returns a string list where every string has had the before text replaced with the after text wherever the before text is found. The before text is matched case-sensitively or not depending on the cs flag.
For example:
QStringList list;
list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings("a", "o");
See also QString::replace().
QStringList & QStringList::replaceInStrings ( const QRegExp & rx, const QString & after )
This is an overloaded function.
Replaces every occurrence of the regexp rx, in each of the string lists's strings, with after. Returns a reference to the string list.
For example:
QStringList list;
list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings(QRegExp("^a"), "o");
For regular expressions that contain capturing parentheses, occurrences of \1, \2, ..., in after are replaced with rx.cap(1), rx.cap(2), ...
For example:
QStringList list;
list << "Bill Clinton" << "Murray, Bill";
list.replaceInStrings(QRegExp("^(.*), (.*)$"), "\\2 \\1");
void QStringList::sort ()
Sorts the list of strings in ascending order (case sensitively).
Sorting is performed using Qt's qSort() algorithm, which operates in linear-logarithmic time, i.e. O(n log n).
If you want to sort your strings in an arbitrary order, consider using the QMap class. For example, you could use a QMap<QString, QString> to create a case-insensitive ordering (e.g. with the keys being lower-case versions of the strings, and the values being the strings), or a QMap<int, QString> to sort the strings by some integer index.
See also qSort().
QStringList QStringList::operator+ ( const QStringList & other ) const
Returns a string list that is the concatenation of this string list with the other string list.
See also append().
QStringList & QStringList::operator<< ( const QString & str )
Appends the given string, str, to this string list and returns a reference to the string list.
See also append().
QStringList & QStringList::operator<< ( const QStringList & other )
This is an overloaded function.
Appends the other string list to the string list and returns a reference to the latter string list.