Qt 4.8
|
The QStringList class provides a list of strings. More...
#include <qstringlist.h>
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... | |
QStringList & | operator<< (const QString &str) |
Appends the given string, str, to this string list and returns a reference to the string list. More... | |
QStringList & | operator<< (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... | |
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. More... | |
QStringList & | replaceInStrings (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 QString & | at (int i) const |
Returns the item at index position i in the list. More... | |
QString & | back () |
This function is provided for STL compatibility. More... | |
const QString & | back () 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... | |
QString & | first () |
Returns a reference to the first item in the list. More... | |
const QString & | first () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
QString & | front () |
This function is provided for STL compatibility. More... | |
const QString & | front () 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 |
QString & | last () |
Returns a reference to the last item in the list. More... | |
const QString & | last () 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< QString > | mid (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< QString > | operator+ (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 QString & | operator[] (int i) const |
Same as at(). More... | |
QString & | operator[] (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< QString > | toSet () const |
Returns a QSet object with the data contained in this QList. More... | |
std::list< QString > | toStdList () const |
Returns a std::list object with the data contained in this QList. More... | |
QVector< QString > | toVector () 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.) | |
QDataStream & | operator<< (QDataStream &out, const QStringList &list) |
Writes the given string list to the specified out stream. More... | |
QDataStream & | operator>> (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... | |
Related Functions inherited from QList< QString > | |
QDataStream & | operator<< (QDataStream &out, const QList< QString > &list) |
Writes the list list to stream out. More... | |
QDataStream & | operator>> (QDataStream &in, QList< QString > &list) |
Reads a list from stream in into list. More... | |
Additional Inherited Members | |
Public Types inherited from QList< QString > | |
typedef const value_type * | const_pointer |
Typedef for const T *. More... | |
typedef const value_type & | const_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_type * | pointer |
Typedef for T *. More... | |
typedef value_type & | reference |
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< QString > | fromSet (const QSet< QString > &set) |
Returns a QList object with the data contained in set. More... | |
static QList< QString > | fromStdList (const std::list< QString > &list) |
Returns a QList object with the data contained in list. More... | |
static QList< QString > | fromVector (const QVector< QString > &vector) |
Returns a QList object with the data contained in vector. More... | |
Public Variables inherited from QList< QString > | |
QListData::Data * | d |
QListData | p |
The QStringList class provides a list of strings.
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:
Strings can be added to a list using the QList::append() , QList::operator+=() and QStringList::operator<<() functions. For example:
To iterate over a list, you can either use index positions or QList's Java-style and STL-style iterator types:
Indexing:
Java-style iterator:
STL-style iterator:
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>.
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:
To break up a string into a string list, use the QString::split() function:
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):
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:
Definition at line 66 of file qstringlist.h.
|
inline |
|
inlineexplicit |
Constructs a string list that contains the given string, str.
Longer lists are easily created like this:
Definition at line 70 of file qstringlist.h.
|
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.
Definition at line 71 of file qstringlist.h.
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.
Definition at line 72 of file qstringlist.h.
|
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.
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().
|
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.
This is equivalent to
Definition at line 167 of file qstringlist.h.
|
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.
|
inline |
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.
Definition at line 195 of file qstringlist.h.
Referenced by ModelNode::changedProperty(), QQnxScreen::connect(), QVNCScreen::connect(), PvrEglScreen::connect(), QLinuxFbScreen::connect(), QLinuxFbIntegration::connect(), QDirectFBScreen::connect(), createReadHandlerHelper(), findAttribute(), if(), imageReadMimeFormats(), imageWriteMimeFormats(), QLibrary::isLibrary(), QDirModel::mkdir(), parseBrushValue(), qExtractSecurityPolicyFromString(), QMultiInputContext::QMultiInputContext(), qt_getDefaultFromHomePrinters(), qt_win_get_open_file_name(), qt_win_get_open_file_names(), qt_win_get_save_file_name(), QWSPcMouseHandlerPrivate::QWSPcMouseHandlerPrivate(), QWSTslibMouseHandlerPrivate::QWSTslibMouseHandlerPrivate(), rasterFallbacksMask(), NestedListModel::set(), QDirectFBScreenPrivate::setFlipFlags(), setIntOption(), and NestedListModel::setProperty().
|
inline |
Definition at line 205 of file qstringlist.h.
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).
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().
|
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.
Definition at line 200 of file qstringlist.h.
|
inline |
Definition at line 210 of file qstringlist.h.
|
inline |
Returns a string list that is the concatenation of this string list with the other string list.
Definition at line 87 of file qstringlist.h.
|
inline |
Appends the given string, str, to this string list and returns a reference to the string list.
Definition at line 89 of file qstringlist.h.
|
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.
|
inline |
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.
Definition at line 157 of file qstringlist.h.
|
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:
Definition at line 177 of file qstringlist.h.
|
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:
For regular expressions that contain capturing parentheses, occurrences of \1, \2, ..., in after are replaced with {rx}.cap(1), {rx}.cap(2), ...
For example:
Definition at line 184 of file qstringlist.h.
|
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.
Definition at line 152 of file qstringlist.h.
Referenced by ControlList::ControlList(), and QFont::substitutions().
|
related |
Writes the given string list to the specified out stream.
Definition at line 252 of file qstringlist.h.
|
related |
Reads a string list from the given in stream into the specified list.
Definition at line 248 of file qstringlist.h.
|
related |
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>.
|
related |
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>.