QStringList(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ‘‘ QStringList β€” the iconic string-list era (3qt)

okay bestie, hydrate, sit down, because we're doing the manual page for QStringList(3qt) and honestly? it's one of the most useful little classes in all of Qt 3. it's giving "quietly carrying the entire codebase" energy. πŸŽ€


πŸ’– NAME

QStringList β€” a list of strings. that's it. that's the whole vibe. a list. of strings. periodt. ✨


🌸 SYNOPSIS

First, the very important disclaimer, bestie β€” read it before you do anything:

All the functions in this class are reentrant when Qt is built with
thread support.</p>

(yes, that </p> is just... sitting there. we don't question it. we love it anyway πŸ’…)

Then you pull it in:

#include <qstringlist.h>

And it Inherits QValueList<QString>. iconic lineage fr fr.

🫢 Public Members

  • QStringList ()
  • QStringList ( const QStringList & l )
  • QStringList ( const QValueList<QString> & l )
  • QStringList ( const QString & i )
  • QStringList ( const char * i )
  • void sort ()
  • QString join ( const QString & sep ) const
  • QStringList grep ( const QString & str, bool cs = TRUE ) const
  • QStringList grep ( const QRegExp & rx ) const
  • QStringList & gres ( const QString & before, const QString & after, bool cs = TRUE )
  • QStringList & gres ( const QRegExp & rx, const QString & after )

🌟 Static Public Members

  • QStringList fromStrList ( const QStrList & ascii )
  • QStringList split ( const QString & sep, const QString & str, bool allowEmptyEntries = FALSE )
  • QStringList split ( const QChar & sep, const QString & str, bool allowEmptyEntries = FALSE )
  • QStringList split ( const QRegExp & sep, const QString & str, bool allowEmptyEntries = FALSE )

πŸ¦‹ DESCRIPTION

The QStringList class provides a list of strings.

It's for storing and manipulating strings that logically belong together. Essentially QStringList is a QValueList of QString objects. And bestie, listen β€” unlike QStrList, which stores pointers to characters, QStringList holds real, whole QString objects. So whenever you're working with Unicode strings, this is the class of choice, no debate. QStringList is part of the Qt Template Library. 🫢

And like QString itself, QStringList objects are implicitly shared, so passing them around as value-parameters is both fast and safe. the way that it's just doing all that for free?? obsessed. 😭

You can add strings to a list using append(), operator+=() or operator<<(), e.g.

QStringList fonts;
fonts.append( "Times" );
fonts += "Courier";
fonts += "Courier New";
fonts << "Helvetica [Cronyx]" << "Helvetica [Adobe]";

String lists have an iterator, QStringList::Iterator(), e.g.

for ( QStringList::Iterator it = fonts.begin(); it != fonts.end(); ++it ) {
    cout << *it << ":";
}
cout << endl;
// Output:
//  Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:
⚠️ real talk: many Qt functions return string lists by value. if you wanna iterate over one of those, make a copy first and iterate over the copy. do not skip this. it's not a suggestion. πŸ’€

You can concatenate all the strings in a string list into a single string (with an optional separator) using join(), e.g.

QString allFonts = fonts.join( ", " );
cout << allFonts << endl;
// Output:
//  Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe]

You can sort the list with sort(), and extract a new list containing only those strings which contain a particular substring (or match a particular regular expression) using the grep() functions, e.g.

fonts.sort();
cout << fonts.join( ", " ) << endl;
// Output:
//  Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times
QStringList helveticas = fonts.grep( "Helvetica" );
cout << helveticas.join( ", " ) << endl;
// Output:
//  Helvetica [Adobe], Helvetica [Cronyx]

Existing strings can be split into string lists with character, string or regular expression separators, e.g.

QString s = "Red\tGreen\tBlue";
QStringList colors = QStringList::split( "\t", s );
cout << colors.join( ", " ) << endl;
// Output:
//  Red, Green, Blue

See also Implicitly and Explicitly Shared Classes, Text Related Classes, and Non-GUI Classes. πŸ’œ


πŸ’… MEMBER FUNCTION DOCUMENTATION

QStringList::QStringList ()

Creates an empty string list. a blank canvas. main character energy from day one. ✨

QStringList::QStringList ( const QStringList & l )

Creates a copy of the list l. And bestie, this function is very fast because QStringList is implicitly shared. In most situations this acts like a deep copy β€” for example, if this list, or the original one, or some other list referencing the same shared data gets modified, the modifying list first makes a copy, i.e. copy-on-write. In a threaded environment you may require a real deep copy. 🧚

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

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

QStringList::QStringList ( const QString & i )

Constructs a string list consisting of the single string i. And longer lists? easily made, watch this:

QStringList items;
items << "Buy" << "Sell" << "Update" << "Value";

ate. πŸ”₯

QStringList::QStringList ( const char * i )

Constructs a string list consisting of the single Latin-1 string i.

QStringList QStringList::fromStrList ( const QStrList & ascii ) [static]

Converts from an ASCII-QStrList ascii to a QStringList (Unicode). glow-up pipeline, basically. πŸ¦‹

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

Returns a list of all the strings containing the substring str.

If cs is TRUE, the grep is done case-sensitively; otherwise case is ignored.

QStringList list;
list << "Bill Gates" << "John Doe" << "Bill Clinton";
list = list.grep( "Bill" );
// list == ["Bill Gates", "Bill Clinton"]

See also QString::find().

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

See also QString::find().

QStringList & QStringList::gres ( const QString & before, const QString & after, bool cs = TRUE )

Replaces every occurrence of the string before in the strings that constitute the string list with the string after. Returns a reference to the string list.

If cs is TRUE, the search is case sensitive; otherwise the search is case insensitive.

Example:

QStringList list;
list << "alpha" << "beta" << "gamma" << "epsilon";
list.gres( "a", "o" );
// list == ["olpho", "beto", "gommo", "epsilon"]

See also QString::replace().

QStringList & QStringList::gres ( const QRegExp & rx, const QString & after )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Replaces every occurrence of the regexp rx in the string with after. Returns a reference to the string list.

Example:

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

For regexps containing capturing parentheses, occurrences of &#92;1, &#92;2, ..., in after are replaced with rx.cap(1), cap(2), ...

Example:

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

See also QString::replace().

QString QStringList::join ( const QString & sep ) const

Joins the string list into a single string, with each element separated by the string sep (which can be empty).

See also split().

Examples:

πŸ™ˆ okay so the original literally just says Examples: and then... nothing. no example. the void. we're keeping it though, because fidelity is the moment and we don't delete things in this house. πŸ’–

void QStringList::sort ()

Sorts the list of strings in ascending case-sensitive order.

Sorting is very fast. It uses the Qt Template Library's efficient HeapSort implementation that has a time complexity of O(n*log n). no cap, that's the actual complexity. πŸ”₯

If you want to sort your strings in an arbitrary order, consider using a QMap. For example you could use a QMap<QString,QString> to create a case-insensitive ordering (e.g. mapping the lowercase text to the text), or a QMap<int,QString> to sort the strings by some integer index, etc.

Example: themes/themes.cpp.

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

Splits the string str into strings wherever the regular expression sep occurs, and returns the list of those strings.

If allowEmptyEntries is TRUE, a null string is inserted in the list wherever the separator matches twice without intervening text.

For example, if you split the string "a,,b,c" on commas, split() returns the three-item list "a", "b", "c" if allowEmptyEntries is FALSE (the default), and the four-item list "a", "", "b", "c" if allowEmptyEntries is TRUE.

If sep does not match anywhere in str, split() returns a single element list with the element containing the single string str.

See also join() and QString::section().

Examples:

🫠 yep. same situation. Examples: and then silence. the mystery continues. we move on, bestie. πŸŽ€

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version of the function uses a QString as separator, rather than a regular expression.

If sep is an empty string, the return value is a list of one-character strings: split( QString( "" ), "four" ) returns the four-item list, "f", "o", "u", "r".

If allowEmptyEntries is TRUE, a null string is inserted in the list wherever the separator matches twice without intervening text.

See also join() and QString::section().

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

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This version of the function uses a QChar as separator, rather than a regular expression.

See also join() and QString::section().


🌈 SEE ALSO


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


✍️ AUTHOR

Generated automatically from the source code.

(no human wrote this. a machine did. and honestly? it ate. πŸ€–βœ¨)


πŸ› BUGS

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. πŸ’–

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. 😭

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qstringlist.3qt) and the Qt version (3.3.8). that last bit is lowkey the most important part, don't skip it bestie, they need the deets. 🫢


and that's the whole page, bestie. this one came from Trolltech AS, dated 2 February 2007, and it's the QStringList(3qt) manual β€” go forth and manipulate some strings. slay. πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from