📄 qstringlist.3qt
字号:
'\" t.TH QStringList 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQStringList \- List of strings.SH SYNOPSISAll the functions in this class are reentrant when Qt is built with thread support.</p>.PP\fC#include <qstringlist.h>\fR.PPInherits QValueList<QString>..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQStringList\fR ()".br.ti -1c.BI "\fBQStringList\fR ( const QStringList & l )".br.ti -1c.BI "\fBQStringList\fR ( const QValueList<QString> & l )".br.ti -1c.BI "\fBQStringList\fR ( const QString & i )".br.ti -1c.BI "\fBQStringList\fR ( const char * i )".br.ti -1c.BI "void \fBsort\fR ()".br.ti -1c.BI "QString \fBjoin\fR ( const QString & sep ) const".br.ti -1c.BI "QStringList \fBgrep\fR ( const QString & str, bool cs = TRUE ) const".br.ti -1c.BI "QStringList \fBgrep\fR ( const QRegExp & expr ) const".br.in -1c.SS "Static Public Members".in +1c.ti -1c.BI "QStringList \fBfromStrList\fR ( const QStrList & ascii )".br.ti -1c.BI "QStringList \fBsplit\fR ( const QString & sep, const QString & str, bool allowEmptyEntries = FALSE )".br.ti -1c.BI "QStringList \fBsplit\fR ( const QChar & sep, const QString & str, bool allowEmptyEntries = FALSE )".br.ti -1c.BI "QStringList \fBsplit\fR ( const QRegExp & sep, const QString & str, bool allowEmptyEntries = FALSE )".br.in -1c.SH DESCRIPTIONThe QStringList class provides a list of strings..PPIt is used to store and manipulate strings that logically belong together. Essentially QStringList is a QValueList of QString objects. Unlike QStrList, which stores pointers to characters, QStringList holds real QString objects. It is the class of choice whenever you work with Unicode strings. QStringList is part of the Qt Template Library..PPLike QString itself, QStringList objects are implicitly shared. Passing them around as value-parameters is both fast and safe..PPStrings can be added to a list using append(), operator+=() or operator<<(), e.g..PP.nf.br QStringList fonts;.br fonts.append( "Times" );.br fonts += "Courier";.br fonts += "Courier New";.br fonts << "Helvetica [Cronyx]" << "Helvetica [Adobe]";.br.fi.PPString lists have an iterator, QStringList::Iterator(), e.g..PP.nf.br for ( QStringList::Iterator it = fonts.begin(); it != fonts.end(); ++it ) {.br cout << *it << ":";.br }.br cout << endl;.br // Output:.br // Times:Courier:Courier New:Helvetica [Cronyx]:Helvetica [Adobe]:.br.fi.PPMany Qt functions return const string lists; to iterate over these you should make a copy and iterate over the copy..PPYou can concatenate all the strings in a string list into a single string (with an optional separator) using join(), e.g..PP.nf.br QString allFonts = fonts.join( ", " );.br cout << allFonts << endl;.br // Output:.br // Times, Courier, Courier New, Helvetica [Cronyx], Helvetica [Adobe].br.fi.PPYou can sort the 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 grep() functions, e.g..PP.nf.br fonts.sort();.br cout << fonts.join( ", " ) << endl;.br // Output:.br // Courier, Courier New, Helvetica [Adobe], Helvetica [Cronyx], Times.br.br QStringList helveticas = fonts.grep( "Helvetica" );.br cout << helveticas.join( ", " ) << endl;.br // Output:.br // Helvetica [Adobe], Helvetica [Cronyx].br.fi.PPExisting strings can be split into string lists with character, string or regular expression separators, e.g..PP.nf.br QString s = "Red\\tGreen\\tBlue";.br QStringList colors = QStringList::split( "\\t", s );.br cout << colors.join( ", " ) << endl;.br // Output:.br // Red, Green, Blue.br.fi.PPSee also Implicitly and Explicitly Shared Classes, Text Related Classes, and Non-GUI Classes..SH MEMBER FUNCTION DOCUMENTATION.SH "QStringList::QStringList ()"Creates an empty string list..SH "QStringList::QStringList ( const QStringList & l )"Creates a copy of the list \fIl\fR. 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 is modified, the modifying list first makes a copy, i.e. copy-on-write. In a threaded environment you may require a real deep copy..SH "QStringList::QStringList ( const QValueList<QString> & l )"Constructs a new string list that is a copy of \fIl\fR..SH "QStringList::QStringList ( const QString & i )"Constructs a string list consisting of the single string \fIi\fR. Longer lists are easily created as follows:.PP.nf.br QStringList items;.br items << "Buy" << "Sell" << "Update" << "Value";.br.fi.SH "QStringList::QStringList ( const char * i )"Constructs a string list consisting of the single latin-1 string \fIi\fR..SH "QStringList QStringList::fromStrList ( const QStrList & ascii )\fC [static]\fR"Converts from an ASCII-QStrList \fIascii\fR to a QStringList (Unicode)..SH "QStringList QStringList::grep ( const QString & str, bool cs = TRUE ) const"Returns a list of all strings containing the substring \fIstr\fR..PPIf \fIcs\fR is TRUE, the grep is done case-sensitively; otherwise case is ignored..SH "QStringList QStringList::grep ( const QRegExp & expr ) const"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPReturns a list of all the strings that match the regular expression \fIexpr\fR..SH "QString QStringList::join ( const QString & sep ) const"Joins the string list into a single string with each element separated by the string \fIsep\fR (which can be empty)..PPSee also split()..SH "void QStringList::sort ()"Sorts the list of strings in ascending case-sensitive order..PPSorting is very fast. It uses the Qt Template Library's efficient HeapSort implementation that has a time complexity of O(n*log n)..PPIf 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..PPExample: themes/themes.cpp..SH "QStringList QStringList::split ( const QRegExp & sep, const QString & str, bool allowEmptyEntries = FALSE )\fC [static]\fR"Splits the string \fIstr\fR into strings wherever the regular expression \fIsep\fR occurs, and returns the list of those strings..PPIf \fIallowEmptyEntries\fR is TRUE, an empty string is inserted in the list wherever the separator matches twice without intervening text..PPFor example, if you split the string "a,,b,c" on commas, split() returns the three-item list "a", "b", "c" if \fIallowEmptyEntries\fR is FALSE (the default), and the four-item list "a", "", "b", "c" if \fIallowEmptyEntries\fR is TRUE..PPIf \fIsep\fR does not match anywhere in \fIstr\fR, split() returns a list consisting of the single string \fIstr\fR..PPSee also join() and QString::section()..PPExamples:.)l chart/element.cpp, dirview/dirview.cpp, and network/httpd/httpd.cpp..SH "QStringList QStringList::split ( const QString & sep, const QString & str, bool allowEmptyEntries = FALSE )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThis version of the function uses a QString as separator, rather than a regular expression..PPIf \fIsep\fR 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"..PPIf \fIallowEmptyEntries\fR is TRUE, an empty string is inserted in the list wherever the separator matches twice without intervening text..PPSee also join() and QString::section()..SH "QStringList QStringList::split ( const QChar & sep, const QString & str, bool allowEmptyEntries = FALSE )\fC [static]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPThis version of the function uses a QChar as separator, rather than a regular expression..PPSee also join() and QString::section()..SH "SEE ALSO".BR http://doc.trolltech.com/qstringlist.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qstringlist.3qt) and the Qtversion (3.1.1).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -