Qt 4.8
Public Functions | Related Functions | List of all members
QStringList Class Reference

The QStringList class provides a list of strings. More...

#include <qstringlist.h>

Inheritance diagram for QStringList:
QList< QString >

Public Functions

QBool contains (const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Returns true if the list contains the string str; otherwise returns false. More...
 
QStringList filter (const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
 Returns a list of all the strings containing the substring str. More...
 
QStringList filter (const QRegExp &rx) const
 Returns a list of all the strings that match the regular expression rx. More...
 
int 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. More...
 
int indexOf (QRegExp &rx, int from=0) const
 
QString join (const QString &sep) 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). More...
 
int 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. More...
 
int lastIndexOf (QRegExp &rx, int from=-1) const
 
QStringList operator+ (const QStringList &other) const
 Returns a string list that is the concatenation of this string list with the other string list. More...
 
QStringListoperator<< (const QString &str)
 Appends the given string, str, to this string list and returns a reference to the string list. More...
 
QStringListoperator<< (const QStringList &l)
 Appends the other string list to the string list and returns a reference to the latter string list. More...
 
 QStringList ()
 Constructs an empty string list. More...
 
 QStringList (const QString &i)
 Constructs a string list that contains the given string, str. More...
 
 QStringList (const QStringList &l)
 Constructs a copy of the other string list. More...
 
 QStringList (const QList< QString > &l)
 Constructs a copy of other. More...
 
int removeDuplicates ()
 This function removes duplicate entries from a list. More...
 
QStringListreplaceInStrings (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. More...
 
QStringListreplaceInStrings (const QRegExp &rx, const QString &after)
 Replaces every occurrence of the regexp rx, in each of the string lists's strings, with after. More...
 
void sort ()
 Sorts the list of strings in ascending order (case sensitively). More...
 
- Public Functions inherited from QList< QString >
void append (const QString &t)
 Inserts value at the end of the list. More...
 
void append (const QList< QString > &t)
 Appends the items of the value list to this list. More...
 
const QStringat (int i) const
 Returns the item at index position i in the list. More...
 
QStringback ()
 This function is provided for STL compatibility. More...
 
const QStringback () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
iterator begin ()
 Returns an STL-style iterator pointing to the first item in the list. More...
 
const_iterator begin () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void clear ()
 Removes all items from the list. More...
 
const_iterator constBegin () const
 Returns a const STL-style iterator pointing to the first item in the list. More...
 
const_iterator constEnd () const
 Returns a const STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
QBool contains (const QString &t) const
 Returns true if the list contains an occurrence of value; otherwise returns false. More...
 
int count (const QString &t) const
 Returns the number of occurrences of value in the list. More...
 
int count () const
 Returns the number of items in the list. More...
 
void detach ()
 
void detachShared ()
 This prevents needless mallocs, and makes QList more exception safe in case of cleanup work done in destructors on empty lists. More...
 
bool empty () const
 This function is provided for STL compatibility. More...
 
iterator end ()
 Returns an STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
const_iterator end () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
bool endsWith (const QString &t) const
 Returns true if this list is not empty and its last item is equal to value; otherwise returns false. More...
 
iterator erase (iterator pos)
 Removes the item associated with the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()). More...
 
iterator erase (iterator first, iterator last)
 Removes all the items from begin up to (but not including) end. More...
 
QStringfirst ()
 Returns a reference to the first item in the list. More...
 
const QStringfirst () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QStringfront ()
 This function is provided for STL compatibility. More...
 
const QStringfront () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int indexOf (const QString &t, int from=0) const
 Returns the index position of the first occurrence of value in the list, searching forward from index position from. More...
 
void insert (int i, const QString &t)
 Inserts value at index position i in the list. More...
 
iterator insert (iterator before, const QString &t)
 Inserts value in front of the item pointed to by the iterator before. More...
 
bool isDetached () const
 
bool isEmpty () const
 Returns true if the list contains no items; otherwise returns false. More...
 
bool isSharedWith (const QList< QString > &other) const
 
QStringlast ()
 Returns a reference to the last item in the list. More...
 
const QStringlast () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
int lastIndexOf (const QString &t, int from=-1) const
 Returns the index position of the last occurrence of value in the list, searching backward from index position from. More...
 
int length () const
 This function is identical to count(). More...
 
QList< QStringmid (int pos, int length=-1) const
 Returns a list whose elements are copied from this list, starting at position pos. More...
 
void move (int from, int to)
 Moves the item at index position from to index position to. More...
 
bool operator!= (const QList< QString > &l) const
 Returns true if other is not equal to this list; otherwise returns false. More...
 
QList< QStringoperator+ (const QList< QString > &l) const
 Returns a list that contains all the items in this list followed by all the items in the other list. More...
 
QList< QString > & operator+= (const QList< QString > &l)
 Appends the items of the other list to this list and returns a reference to this list. More...
 
QList< QString > & operator+= (const QString &t)
 Appends value to the list. More...
 
QList< QString > & operator<< (const QList< QString > &l)
 Appends the items of the other list to this list and returns a reference to this list. More...
 
QList< QString > & operator<< (const QString &t)
 Appends value to the list. More...
 
QList< QString > & operator= (const QList< QString > &l)
 Assigns other to this list and returns a reference to this list. More...
 
bool operator== (const QList< QString > &l) const
 Returns true if other is equal to this list; otherwise returns false. More...
 
const QStringoperator[] (int i) const
 Same as at(). More...
 
QStringoperator[] (int i)
 Returns the item at index position i as a modifiable reference. More...
 
void pop_back ()
 This function is provided for STL compatibility. More...
 
void pop_front ()
 This function is provided for STL compatibility. More...
 
void prepend (const QString &t)
 Inserts value at the beginning of the list. More...
 
void push_back (const QString &t)
 This function is provided for STL compatibility. More...
 
void push_front (const QString &t)
 This function is provided for STL compatibility. More...
 
 QList ()
 Constructs an empty list. More...
 
 QList (const QList< QString > &l)
 Constructs a copy of other. More...
 
int removeAll (const QString &t)
 Removes all occurrences of value in the list and returns the number of entries removed. More...
 
void removeAt (int i)
 Removes the item at index position i. More...
 
void removeFirst ()
 Removes the first item in the list. More...
 
void removeLast ()
 Removes the last item in the list. More...
 
bool removeOne (const QString &t)
 Removes the first occurrence of value in the list and returns true on success; otherwise returns false. More...
 
void replace (int i, const QString &t)
 Replaces the item at index position i with value. More...
 
void reserve (int size)
 Reserve space for alloc elements. More...
 
void setSharable (bool sharable)
 
int size () const
 Returns the number of items in the list. More...
 
bool startsWith (const QString &t) const
 Returns true if this list is not empty and its first item is equal to value; otherwise returns false. More...
 
void swap (QList< QString > &other)
 Swaps list other with this list. More...
 
void swap (int i, int j)
 Exchange the item at index position i with the item at index position j. More...
 
QString takeAt (int i)
 Removes the item at index position i and returns it. More...
 
QString takeFirst ()
 Removes the first item in the list and returns it. More...
 
QString takeLast ()
 Removes the last item in the list and returns it. More...
 
QSet< QStringtoSet () const
 Returns a QSet object with the data contained in this QList. More...
 
std::list< QStringtoStdList () const
 Returns a std::list object with the data contained in this QList. More...
 
QVector< QStringtoVector () const
 Returns a QVector object with the data contained in this QList. More...
 
QString value (int i) const
 Returns the value at index position i in the list. More...
 
QString value (int i, const QString &defaultValue) const
 If the index i is out of bounds, the function returns defaultValue. More...
 
 ~QList ()
 Destroys the list. More...
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator<< (QDataStream &out, const QStringList &list)
 Writes the given string list to the specified out stream. More...
 
QDataStreamoperator>> (QDataStream &in, QStringList &list)
 Reads a string list from the given in stream into the specified list. More...
 
 QMutableStringListIterator
 The QStringListIterator type definition provides a Java-style non-const iterator for QStringList. More...
 
 QStringListIterator
 The QStringListIterator type definition provides a Java-style const iterator for QStringList. More...
 

Additional Inherited Members

- Public Types inherited from QList< QString >
typedef const value_typeconst_pointer
 Typedef for const T *. More...
 
typedef const value_typeconst_reference
 Typedef for const T &. More...
 
typedef const_iterator ConstIterator
 Qt-style synonym for QList::const_iterator. More...
 
typedef qptrdiff difference_type
 Typedef for ptrdiff_t. More...
 
typedef iterator Iterator
 Qt-style synonym for QList::iterator. More...
 
typedef value_typepointer
 Typedef for T *. More...
 
typedef value_typereference
 Typedef for T &. More...
 
typedef int size_type
 Typedef for int. More...
 
typedef QString value_type
 Typedef for T. More...
 
- Static Public Functions inherited from QList< QString >
static QList< QStringfromSet (const QSet< QString > &set)
 Returns a QList object with the data contained in set. More...
 
static QList< QStringfromStdList (const std::list< QString > &list)
 Returns a QList object with the data contained in list. More...
 
static QList< QStringfromVector (const QVector< QString > &vector)
 Returns a QList object with the data contained in vector. More...
 
- Public Variables inherited from QList< QString >
QListData::Datad
 
QListData p
 

Detailed Description

The QStringList class provides a list of strings.

Note
This class or function is reentrant.

QStringList inherits from QList<QString>. Like QList, QStringList is implicitly shared. It provides fast index-based access as well as fast insertions and removals. Passing string lists as value parameters is both fast and safe.

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(), removeAll(), removeAt(), removeFirst(), removeLast(), and removeOne() to modify a QStringList. In addition, QStringList provides a few convenience functions that make handling lists of strings easier:

Adding strings

Strings can be added to a list using the QList::append() , QList::operator+=() and QStringList::operator<<() functions. For example:

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

Iterating over the strings

To iterate over a list, you can either use index positions or QList's Java-style and STL-style iterator types:

Indexing:

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

Java-style iterator:

QStringListIterator javaStyleIterator(fonts);
while (javaStyleIterator.hasNext())
cout << javaStyleIterator.next().toLocal8Bit().constData() << endl;

STL-style iterator:

for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd();
++constIterator)
cout << (*constIterator).toLocal8Bit().constData() << endl;

The QStringListIterator class is simply a type definition for QListIterator<QString>. QStringList also provide the QMutableStringListIterator class which is a type definition for QMutableListIterator<QString>.

Manipulating the strings

QStringList provides several functions allowing you to manipulate the contents of a list. You can concatenate all the strings in a string list into a single string (with an optional separator) using the join() function. For example:

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

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

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

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

In addition, the QStringList::operator+(){operator+()} function allows you to concatenate two string lists into one. To sort a string list, use the sort() function.

QString list also provides the filter() function which lets you to extract a new list which contains only those strings which contain a particular substring (or match a particular regular expression):

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

The contains() function tells you whether the list contains a given string, while the indexOf() function returns the index of the first occurrence of the given string. The lastIndexOf() function on the other hand, returns the index of the last occurrence of the string.

Finally, the replaceInStrings() function calls QString::replace() on each string in the string list in turn. For example:

QStringList files;
files << "$QTDIR/src/moc/moc.y"
<< "$QTDIR/src/moc/moc.l"
<< "$QTDIR/include/qconfig.h";
files.replaceInStrings("$QTDIR", "/usr/lib/qt");
// files: [ "/usr/lib/qt/src/moc/moc.y", ...]
See also
QString

Definition at line 66 of file qstringlist.h.

Constructors and Destructors

◆ QStringList() [1/4]

QStringList::QStringList ( )
inline

Constructs an empty string list.

Definition at line 69 of file qstringlist.h.

69 { }

◆ QStringList() [2/4]

QStringList::QStringList ( const QString str)
inlineexplicit

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()

Definition at line 70 of file qstringlist.h.

70 { append(i); }
void append(const QString &t)
Inserts value at the end of the list.
Definition: qlist.h:507

◆ QStringList() [3/4]

QStringList::QStringList ( const QStringList other)
inline

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=()

Definition at line 71 of file qstringlist.h.

71 : QList<QString>(l) { }
QFactoryLoader * l

◆ QStringList() [4/4]

QStringList::QStringList ( const QList< QString > &  other)
inline

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=()

Definition at line 72 of file qstringlist.h.

72 : QList<QString>(l) { }
QFactoryLoader * l

Functions

◆ contains()

QBool QStringList::contains ( const QString str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

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(), QString::contains()

Definition at line 172 of file qstringlist.h.

Referenced by QFileSystemWatcherPrivate::_q_directoryChanged(), QFileSystemWatcherPrivate::_q_fileChanged(), QPSQLDriver::_q_handleNotification(), QDeclarativeImportDatabase::addImportPath(), QInotifyFileSystemWatcherEngine::addPaths(), QKqueueFileSystemWatcherEngine::addPaths(), QDnotifyFileSystemWatcherEngine::addPaths(), QWindowsFileSystemWatcherEngine::addPaths(), QFSEventsFileSystemWatcherEngine::addPaths(), QPollingFileSystemWatcherEngine::addPaths(), QPatternist::XsdValidatingInstanceReader::addSchema(), QWindowsMime::allMimesForFormats(), QTextControl::anchorPosition(), QCoreApplicationPrivate::appendApplicationPathToLibraryPaths(), QCss::StyleSelector::basicSelectorMatches(), QDeclarativeCompiler::buildObject(), QBuiltInMimes::canConvertFromMime(), QUrlModel::canDrop(), QInternalMimeData::canReadData(), NestedListModel::checkRoles(), QVFbScreen::connect(), QVNCScreen::connect(), PvrEglScreen::connect(), QLinuxFbScreen::connect(), QLinuxFbIntegration::connect(), QDirectFBScreen::connect(), QScriptDebuggerConsolePrivate::createJob(), QDeclarativeXmlQueryEngine::doSubQueryJob(), QSqlDatabase::drivers(), QUrlModel::dropMimeData(), QClipboardWatcher::empty(), QIconLoader::ensureInitialized(), QFontconfigDatabase::fallbacksForFamily(), QScriptDebuggerConsoleCommandManager::findCommand(), QFontDatabase::findFont(), QIconLoader::findIconHelper(), QDeclarativeStateGroupPrivate::findTransition(), QInternalMimeData::formats(), QMacPasteboard::formats(), QXlibClipboardMime::formats_sys(), QBuiltInMimes::formatsForMime(), QInternalMimeData::formatsHelper(), QFileInfoGatherer::getFileInfos(), QFileInfoGatherer::getInfo(), QMimeData::hasFormat(), QWaylandMimeData::hasFormat_sys(), QXlibClipboardMime::hasFormat_sys(), QInternalMimeData::hasFormatHelper(), QFileDialog::history(), QScriptEngine::importExtension(), QApplication::inputContext(), QFont::insertSubstitution(), QFont::insertSubstitutions(), QDBusConnectionPrivate::isServiceRegisteredByThread(), QKde::kdeStyle(), QDecorationFactory::keys(), QStyleFactory::keys(), QMouseDriverFactory::keys(), QScreenDriverFactory::keys(), QGenericPluginFactory::keys(), QKbdDriverFactory::keys(), QGraphicsSystemFactory::keys(), QCoreApplication::libraryPaths(), loadEngine(), loadWin(), QXmlSimpleReaderPrivate::processElementEmptyTag(), QDropEvent::provides(), QIconTheme::QIconTheme(), qt_is_idn_enabled(), QApplicationPrivate::qt_mac_apply_settings(), QFileDialogPrivate::qt_mac_filedialog_event_proc(), QPatternist::XsdValidatingInstanceReader::read(), QDeclarativeDebugConnectionPrivate::readyRead(), QDeclarativeDebugServer::receiveMessage(), QOCIDriver::record(), registerFont(), QTextHtmlParser::resolveStyleSheetImports(), QScanThread::run(), QPrinterDescription::samePrinter(), QNativeWifiEngine::scanComplete(), QAxScriptManager::scriptForFunction(), QCoreApplication::setApplicationVersion(), QMacPasteboard::setMimeData(), QGuiPlatformPlugin::styleName(), QPSQLDriver::subscribeToNotificationImplementation(), QOCIDriver::tables(), QClipboard::text(), QDeclarativePropertyAction::transition(), QDeclarativePropertyAnimation::transition(), uncShareExists(), QPSQLDriver::unsubscribeFromNotificationImplementation(), and QApplicationPrivate::x11_apply_settings().

173 {
174  return QtPrivate::QStringList_contains(this, str, cs);
175 }
QBool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs)

◆ filter() [1/2]

QStringList QStringList::filter ( const QString str,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
) const
inline

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.

list << "Bill Murray" << "John Doe" << "Bill Clinton";
QStringList result;
result = list.filter("Bill");
// result: ["Bill Murray", "Bill Clinton"]

This is equivalent to

QStringList result;
foreach (const QString &str, list) {
if (str.contains("Bill"))
result += str;
}
See also
contains()

Definition at line 167 of file qstringlist.h.

168 {
169  return QtPrivate::QStringList_filter(this, str, cs);
170 }
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs)

◆ filter() [2/2]

QStringList QStringList::filter ( const QRegExp rx) const
inline

Returns a list of all the strings that match the regular expression rx.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 190 of file qstringlist.h.

191 {
192  return QtPrivate::QStringList_filter(this, rx);
193 }
QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs)

◆ indexOf() [1/2]

int QStringList::indexOf ( const QRegExp rx,
int  from = 0 
) const
inline

◆ indexOf() [2/2]

int QStringList::indexOf ( QRegExp rx,
int  from = 0 
) const
inline

Definition at line 205 of file qstringlist.h.

206 {
207  return QtPrivate::QStringList_indexOf(this, rx, from);
208 }
int Q_CORE_EXPORT QStringList_indexOf(const QStringList *that, const QRegExp &rx, int from)

◆ join()

QString QStringList::join ( const QString separator) const
inline

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()

Definition at line 162 of file qstringlist.h.

Referenced by QFileDialogPrivate::_q_selectionChanged(), QFileSystemWatcher::addPaths(), QStyleSheetStyleSelector::attribute(), QScriptEngine::availableExtensions(), QVNCScreen::connect(), QDirectFBScreenPrivate::createPixmapData(), QScriptDebuggerLocalsModel::data(), QPatternist::XsdSchemaDebugger::dumpElement(), QPatternist::TagValidationHandler::finalize(), QDeclarativeXmlQueryEngine::getValuesOfKeyRoles(), QScriptToolTipJob::handleResponse(), QDir::nameFiltersFromString(), operator<<(), QCompleter::pathFromIndex(), qt_parsePrinterDesc(), qt_parsePrintersConf(), qt_win_extract_filter(), QWSPcMouseHandlerPrivate::QWSPcMouseHandlerPrivate(), QWSTslibMouseHandlerPrivate::QWSTslibMouseHandlerPrivate(), rasterFallbacksMask(), QSqlRelationalTableModel::selectStatement(), QGtkStylePrivate::setupGtkFileChooser(), QDeclarativeBindingCompilerPrivate::subscription(), QDeclarativeBindingCompilerPrivate::subscriptionIndex(), QOCIDriver::tables(), QTDSDriver::tables(), QODBCDriver::tables(), QEglProperties::toString(), QPatternist::TagValidationHandler::validate(), QPatternist::MaintainingReader< XSLTTokenLookup >::validateElement(), and QApplicationPrivate::x11_apply_settings().

163 {
164  return QtPrivate::QStringList_join(this, sep);
165 }
QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QString &sep)

◆ lastIndexOf() [1/2]

int QStringList::lastIndexOf ( const QRegExp rx,
int  from = -1 
) const
inline

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(), QRegExp::exactMatch()

Definition at line 200 of file qstringlist.h.

201 {
202  return QtPrivate::QStringList_lastIndexOf(this, rx, from);
203 }
int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from)

◆ lastIndexOf() [2/2]

int QStringList::lastIndexOf ( QRegExp rx,
int  from = -1 
) const
inline

Definition at line 210 of file qstringlist.h.

211 {
212  return QtPrivate::QStringList_lastIndexOf(this, rx, from);
213 }
int Q_CORE_EXPORT QStringList_lastIndexOf(const QStringList *that, const QRegExp &rx, int from)

◆ operator+()

QStringList QStringList::operator+ ( const QStringList other) const
inline

Returns a string list that is the concatenation of this string list with the other string list.

See also
append()

Definition at line 87 of file qstringlist.h.

88  { QStringList n = *this; n += other; return n; }
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

◆ operator<<() [1/2]

QStringList & QStringList::operator<< ( const QString str)
inline

Appends the given string, str, to this string list and returns a reference to the string list.

See also
append()

Definition at line 89 of file qstringlist.h.

90  { append(str); return *this; }
void append(const QString &t)
Inserts value at the end of the list.
Definition: qlist.h:507

◆ operator<<() [2/2]

QStringList & QStringList::operator<< ( const QStringList other)
inline

Appends the other string list to the string list and returns a reference to the latter string list.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 91 of file qstringlist.h.

92  { *this += l; return *this; }
QFactoryLoader * l

◆ removeDuplicates()

int QStringList::removeDuplicates ( )
inline

This function removes duplicate entries from a list.

Since
4.5

The entries do not have to be sorted. They will retain their original order.

Returns the number of removed entries.

Definition at line 157 of file qstringlist.h.

158 {
160 }
int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that)

◆ replaceInStrings() [1/2]

QStringList & QStringList::replaceInStrings ( const QString before,
const QString after,
Qt::CaseSensitivity  cs = Qt::CaseSensitive 
)
inline

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:

list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings("a", "o");
// list == ["olpho", "beto", "gommo", "epsilon"]
See also
QString::replace()

Definition at line 177 of file qstringlist.h.

178 {
179  QtPrivate::QStringList_replaceInStrings(this, before, after, cs);
180  return *this;
181 }
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs)

◆ replaceInStrings() [2/2]

QStringList & QStringList::replaceInStrings ( const QRegExp rx,
const QString after 
)
inline

Replaces every occurrence of the regexp rx, in each of the string lists's strings, with after.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a reference to the string list.

For example:

list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings(QRegExp("^a"), "o");
// list == ["olpha", "beta", "gamma", "epsilon"]

For regular expressions that contain capturing parentheses, occurrences of \1, \2, ..., in after are replaced with {rx}.cap(1), {rx}.cap(2), ...

For example:

list << "Bill Clinton" << "Murray, Bill";
list.replaceInStrings(QRegExp("^(.*), (.*)$"), "\\2 \\1");
// list == ["Bill Clinton", "Bill Murray"]

Definition at line 184 of file qstringlist.h.

185 {
187  return *this;
188 }
void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs)

◆ sort()

void QStringList::sort ( )
inline

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()

Definition at line 152 of file qstringlist.h.

Referenced by ControlList::ControlList(), and QFont::substitutions().

153 {
155 }
void Q_CORE_EXPORT QStringList_sort(QStringList *that)

Friends and Related Functions

◆ operator<<()

QDataStream & operator<< ( QDataStream out,
const QStringList list 
)
related

Writes the given string list to the specified out stream.

See also
{Serializing Qt Data Types}

Definition at line 252 of file qstringlist.h.

253 {
254  return operator<<(out, static_cast<const QList<QString> &>(list));
255 }

◆ operator>>()

QDataStream & operator>> ( QDataStream in,
QStringList list 
)
related

Reads a string list from the given in stream into the specified list.

See also
{Serializing Qt Data Types}

Definition at line 248 of file qstringlist.h.

249 {
250  return operator>>(in, static_cast<QList<QString> &>(list));
251 }
QDataStream & operator>>(QDataStream &in, QStringList &list)
Reads a string list from the given in stream into the specified list.
Definition: qstringlist.h:248

◆ QMutableStringListIterator()

The QStringListIterator type definition provides a Java-style non-const iterator for QStringList.

QStringList provides both Java-style iterators and STL-style iterators. The Java-style non-const iterator is simply a type definition for QMutableListIterator<QString>.

See also
QStringListIterator, QStringList::iterator

◆ QStringListIterator()

The QStringListIterator type definition provides a Java-style const iterator for QStringList.

QStringList provides both Java-style iterators and STL-style iterators. The Java-style const iterator is simply a type definition for QListIterator<QString>.

See also
QMutableStringListIterator, QStringList::const_iterator

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