Qt logo

QStringList Class Reference


A list of strings. More...

#include <qstringlist.h>

Inherits QValueList.

List of all member functions.

Public Members

Static Public Members


Detailed Description

A list of strings.

This class is a list of QString objects. Like QValueList it is value based unlike QList. In contrast to QStrList it deals with real QString objects instead of character pointers. That makes QStringList the class of choice if you have to deal with unicode strings.

Like QString itself, a QStringList provides implicit share. Therefore string lists can be passed around as value-parameters both fast and safe.

Example:

        QStringList list;

        // three different ways of appending values:
        list.append( "Torben");
        list += "Warwick";
        list << "Matthias" << "Arnt" << "Paul";

        // sort the list, Arnt's now first
        list.sort();

        // print it out
        for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
            printf( "%s \n", (*it).latin1() );
        }

There are also convenient static methods available, which make working with QStringLists easy, like multiple split() and grep() methods.


Member Function Documentation

QStringList::QStringList ( const QString & i )

Constructs a string list consisting of the single string i. To make longers lists easily, use:

    QString s1,s2,s3;
    ...
    QStringList mylist = QStringList() << s1 << s2 << s3;

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

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

QStringList::QStringList ( const QStringList & l )

Creates a copy of the list. This function is very fast since QStringList is implicit 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, then the modifying list makes a copy first.

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

Greps in the stringlist for all strings, which contain the regular expression expr and returns a stringlist containing all that strings.

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

Greps in the stringlist for all strings, which contain the string expr and returns a stringlist containing all that strings. If cs is TRUE, the grep is done case sensitive, else not.

void QStringList::sort ()

Sorts the list of strings in ascending order. The sorting algorithm used is HeapSort which operates in O(n*logn).

QStringList QStringList::split ( const QChar & sep, const QString & str, bool allowEmptyEntries = FALSE ) [static]

Splits the string str using sep as separator. Returns the list of strings. If allowEmptyEntries is TRUE, also empty entries are inserted into the list, else not. So if you have a string 'abc..d.e.', a list which contains 'abc', 'd', and 'e' would be returned if allowEmptyEntries is FALSE, but a list containing 'abc', '', 'd', 'e' and '' would be returned if allowEmptyEntries is TRUE. If str doesn't contain sep, a stringlist with one item, which is the same as str, is returned.

QStringList QStringList::split ( const QRegExp & sep, const QString & str, bool allowEmptyEntries = FALSE ) [static]

Splits the string str using the regular expression sep as separator. Returns the list of strings. If allowEmptyEntries is TRUE, also empty entries are inserted into the list, else not. So if you have a string 'abc..d.e.', a list which contains 'abc', 'd', and 'e' would be returned if allowEmptyEntries is FALSE, but a list containing 'abc', '', 'd', 'e' and '' would be returned if allowEmptyEntries is TRUE. If str doesn't contain sep, a stringlist with one item, which is the same as str, is returned.

QStringList QStringList::split ( const QString & sep, const QString & str, bool allowEmptyEntries = FALSE ) [static]

Splits the string str using sep as separator. Returns the list of strings. If allowEmptyEntries is TRUE, also empty entries are inserted into the list, else not. So if you have a string 'abc..d.e.', a list which contains 'abc', 'd', and 'e' would be returned if allowEmptyEntries is FALSE, but a list containing 'abc', '', 'd', 'e' and '' would be returned if allowEmptyEntries is TRUE. If str doesn't contain sep, a stringlist with one item, which is the same as str, is returned.


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright İ 1999 Troll TechTrademarks
Qt version 2.1.0 (pre-release)