Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QStringList Class Reference

Inheritance diagram for QStringList:

QList< QString >

List of all members.


Detailed Description

The QStringList class provides a list of strings.

QStringList inherits from QList<QString>. All of QList's functionality also applies to QStringList. For example, you can use isEmpty() to test whether the list is empty, and you can call functions like append(), prepend(), insert(), replace(), and remove() to modify a QStringList. In addition, QStringList provides a few convenience functions that make handling lists of strings easier.

Like QList, QStringList is {implicitly shared}. QStringList provides fast index-based access as well as fast insertions and removals. Passing string lists as value parameters is both fast and safe.

Strings can be added to a list using append(), operator+=(), or operator<<(). For example:

        QStringList fonts;
        fonts << "Arial" << "Helvetica" << "Times" << "Courier";

To iterate over a string, you can either use index positions or QList's Java-style and STL-style iterator types. Here are examples of each approach.

Indexing:

        for (int i = 0; i < fonts.size(); ++i)
            cout << fonts.at(i).ascii() << endl;

Java-style iterator:

        QStringListIterator i(fonts);
        while (i.hasNext())
            cout << i.next().ascii() << endl;

STL-style iterator:

        QStringList::const_iterator i;
        for (i = fonts.constBegin(); i != fonts.constEnd(); ++i)
            cout << (*i).ascii() << endl;

QStringListIterator and QMutableStringListIterator are simply typedefs for QListIterator<QString> and QMutableListIterator<QString>.

You can concatenate all the strings in a string list into a single string (with an optional separator) using join(). For example:

        QString str = fonts.join(",");
        // str == "Arial,Helvetica,Times,Courier"

To break up a string into a string list, use QString::split():

        QString str = "Arial,Helvetica,Times,Courier";
        QStringList list = str.split(",");
        // list: ["Arial", "Helvetica", "Times", "Courier"]

The argument to split can be a single character, a string, or a QRegExp.

You can sort a string list with sort(), and extract a new list which contains only those strings which contain a particular substring (or match a particular regular expression) using the find() functions. For example:

        QStringList monospacedFonts = fonts.find(QRegExp("Courier|Fixed"));

Similarly, the replace() function calls QString::replace() on each string in the string list in turn. Here's an example that uses it to replace all occurrences of "$QTDIR" with "/usr/lib/qt" in a string list:

        QStringList files;
        files << "$QTDIR/src/moc/moc.y"
              << "$QTDIR/src/moc/moc.l"
              << "$QTDIR/include/qconfig.h";

        files.replace("$QTDIR", "/usr/lib/qt");

See also:
QString, QStringListIterator, QMutableStringListIterator

Definition at line 44 of file qstringlist.h.


Public Types

typedef const value_typeconst_pointer
typedef const value_typeconst_reference
typedef const_iterator ConstIterator
typedef iterator Iterator
typedef value_typepointer
typedef value_typereference
typedef int size_type
typedef QString value_type

Public Member Functions

void append (const QString &t)
const QStringat (int i) const
const QStringback () const
QStringback ()
const_iterator begin () const
iterator begin ()
void clear ()
const_iterator constBegin () const
const_iterator constEnd () const
QBool contains (const QString &t) const
QBool contains (const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
int count () const
int count (const QString &t) const
void detach ()
bool empty () const
const_iterator end () const
iterator end ()
iterator erase (iterator first, iterator last)
iterator erase (iterator pos)
QStringList filter (const QRegExp &rx) const
QStringList filter (const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
const QStringfirst () const
QStringfirst ()
const QStringfront () const
QStringfront ()
int indexOf (const QString &t, int from=0) const
int indexOf (const QRegExp &rx, int from=0) const
iterator insert (iterator before, const QString &t)
void insert (int i, const QString &t)
bool isDetached () const
bool isEmpty () const
QString join (const QString &sep) const
const QStringlast () const
QStringlast ()
int lastIndexOf (const QString &t, int from=-1) const
int lastIndexOf (const QRegExp &rx, int from=-1) const
QList< QStringmid (int pos, int length=-1) const
void move (int from, int to)
bool operator!= (const QList< QString > &l) const
QList< QStringoperator+ (const QList< QString > &l) const
QStringList operator+ (const QStringList &other) const
QList< QString > & operator+= (const QString &t)
QList< QString > & operator+= (const QList< QString > &l)
QList< QString > & operator<< (const QList< QString > &l)
QStringListoperator<< (const QStringList &l)
QStringListoperator<< (const QString &str)
bool operator== (const QList< QString > &l) const
QStringoperator[] (int i)
const QStringoperator[] (int i) const
void pop_back ()
void pop_front ()
void prepend (const QString &t)
void push_back (const QString &t)
void push_front (const QString &t)
 QStringList (const QList< QString > &l)
 QStringList (const QStringList &l)
 QStringList (const QString &i)
 QStringList ()
int removeAll (const QString &t)
void removeAt (int i)
void removeFirst ()
void removeLast ()
void replace (int i, const QString &t)
QStringListreplaceInStrings (const QRegExp &rx, const QString &after)
QStringListreplaceInStrings (const QString &before, const QString &after, Qt::CaseSensitivity cs=Qt::CaseSensitive)
void setSharable (bool sharable)
int size () const
void sort ()
void swap (int i, int j)
QString takeAt (int i)
QString takeFirst ()
QString takeLast ()
QSet< QStringtoSet () const
std::list< QStringtoStdList () const
QVector< QStringtoVector () const
QString value (int i, const QString &defaultValue) const
QString value (int i) const

Static Public Member Functions

static QList< QStringfromSet (const QSet< QString > &set)
static QList< QStringfromStdList (const std::list< QString > &list)
static QList< QStringfromVector (const QVector< QString > &vector)

Public Attributes

QListData::Data * d
QListData p

Friends

class const_iterator
class iterator

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QStringList &list)
QDataStreamoperator>> (QDataStream &in, QStringList &list)
 QMutableStringListIterator
 QStringListIterator

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index