QStringList Class Reference
[QtCore module]
QStringList中的类提供的字符串列表。More…
Methods
__init__ (self)
__init__ (self, QString i)
__init__ (self, QStringList l)
append (self, QString str)
clear (self)
bool contains (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
int count (self, QString str)
int count (self)
QStringList filter (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
QStringList filter (self, QRegExp rx)
QString first (self)
int indexOf (self, QString value, int from = 0)
int indexOf (self, QRegExp rx, int from = 0)
insert (self, int i, QString str)
bool isEmpty (self)
QString join (self, QString sep)
QString last (self)
int lastIndexOf (self, QString value, int from = -1)
int lastIndexOf (self, QRegExp rx, int from = -1)
QStringList mid (self, int pos, int length = -1)
move (self, int from, int to)
prepend (self, QString str)
int removeAll (self, QString str)
removeAt (self, int i)
int removeDuplicates (self)
replace (self, int i, QString str)
QStringList replaceInStrings (self, QString before, QString after, Qt.CaseSensitivity cs = Qt.CaseSensitive)
QStringList replaceInStrings (self, QRegExp rx, QString after)
sort (self)
swap (self, int i, int j)
QString takeAt (self, int i)
QString takeFirst (self)
QString takeLast (self)
Special Methods
QStringList __add__ (self, QStringList other)
int __contains__ (self, QString str)
__delitem__ (self, int i)
__delitem__ (self, slice slice)
bool __eq__ (self, QStringList other)
QString __getitem__ (self, int i)
QStringList __getitem__ (self, slice slice)
QStringList __iadd__ (self, QStringList other)
QStringList __iadd__ (self, QString value)
QStringList __imul__ (self, int by)
__len__ (self)
QStringList __lshift__ (self, QString str)
QStringList __lshift__ (self, QStringList l)
QStringList __mul__ (self, int by)
bool __ne__ (self, QStringList other)
__setitem__ (self, int i, QString str)
__setitem__ (self, slice slice, QStringList list)
Detailed Description
Python字符串或Unicode对象的Python列表或QString实例可用于每当一个QStringList预计。
QStringList中的类提供的字符串列表。
QStringList中的继承QList\u003cQString\u003e 。喜欢QList, QStringList中是implicitly shared。它提供了快速基于索引的访问以及快速插入和删除。传递字符串列表作为值参数既快速又安全。
所有QList的功能也适用于QStringList中。例如,您可以使用isEmpty( )来测试列表是否为空,你可以调用函数如append( )prepend( )insert( )replace( )removeAll( )removeAt( )removeFirst( )removeLast()和removeOne( )来修改一个QStringList中。此外, QStringList中提供了一些方便的功能,使操作字符串容易列表:
Adding strings
字符串可以使用被添加到列表中的append(),operator+=()和operator<<()函数。例如:
QStringList fonts;
fonts << "Arial" << "Helvetica" << "Times" << "Courier";
Iterating over the strings
遍历一个列表,你可以使用的索引位置,或QList的Java风格和STL风格的迭代器类型:
索引:
for (int i = 0; i < fonts.size(); ++i)
cout << fonts.at(i).toLocal8Bit().constData() << endl;
Java风格的迭代器:
[QStringListIterator]($docs-qstringlist.html#QStringListIterator-typedef) javaStyleIterator(fonts);
while (javaStyleIterator.hasNext())
cout << javaStyleIterator.next().toLocal8Bit().constData() << endl;
STL风格的迭代器:
QStringList.const_iterator constIterator;
for (constIterator = fonts.constBegin(); constIterator != fonts.constEnd();
++constIterator)
cout << (*constIterator).toLocal8Bit().constData() << endl;
该QStringListIterator类只是一个类型定义QListIterator\u003cQString\u003e 。 QStringList中还提供了QMutableStringListIterator类,这是一个类型定义QMutableListIterator\u003cQString\u003e 。
Manipulating the strings
QStringList中提供了几个功能,让你操作一个列表的内容。您可以使用串连在一个字符串列表转换成一个字符串的所有字符串(带有可选的分隔符)的join()函数。例如:
[QString]($docs-qstring.html) str = fonts.join(",");
// str == "Arial,Helvetica,Times,Courier"
打破一个字符串转换成一个字符串列表,使用QString.split( )函数:
QStringList list;
list = str.split(",");
// list: ["Arial", "Helvetica", "Times", "Courier"]
该参数分割可以是单个字符,字符串,或QRegExp。
此外,该operator+( )功能可让您连接两个字符串列表为一体。要排序的字符串列表,使用sort()函数。
QString名单中还提供了filter( )函数,它可以让你提取一个新的列表,其中包含只有那些包含特定字符串(或匹配特定的正则表达式)字符串:
QStringList monospacedFonts = fonts.filter([QRegExp]($docs-qregexp.html)("Courier|Fixed"));
该contains( )函数告诉你的列表中是否包含给定的字符串,而indexOf( )函数返回给定字符串的第一个匹配项的索引。该lastIndexOf在另一方面( )函数,返回字符串中最后一次出现的索引。
最后,该replaceInStrings( )函数调用QString.replace( )在字符串列表中依次每个字符串。例如:
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", ...]
Method Documentation
QStringList.__init__ (self)
构造一个空字符串列表。
QStringList.__init__ (self, QString i)
构造一个字符串列表,其中包含给定的字符串,str。较长的列表很容易像这样创建:
[QStringList]($docs-qstringlist.html) longerList = ([QStringList]($docs-qstringlist.html)() << str1 << str2 << str3);
See also append( ) 。
QStringList.__init__ (self, QStringList l)
构造的一个副本other字符串列表。
该操作需要constant time因为QStringList is implicitly shared,使得返回一个过程QStringList从非常快的函数。如果共享的实例被改性时,其将被复制(复制写入时) ,而这需要linear time。
See also operator=( ) 。
QStringList.append (self, QString str)
QStringList.clear (self)
bool QStringList.contains (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
如果列表中包含该字符串,则返回Truestr否则返回False 。搜索不区分大小写,如果cs is Qt.CaseInsensitive;搜索是区分默认敏感。
See also indexOf( )lastIndexOf()和QString.contains( ) 。
int QStringList.count (self, QString str)
int QStringList.count (self)
QStringList QStringList.filter (self, QString str, Qt.CaseSensitivity cs = Qt.CaseSensitive)
返回所有的字符串包含子列表str。
If cs is Qt.CaseSensitive(默认值) ,字符串比较是区分大小写的,否则比较不区分大小写。
[QStringList]($docs-qstringlist.html) list;
list << "Bill Murray" << "John Doe" << "Bill Clinton";
[QStringList]($docs-qstringlist.html) result;
result = list.filter("Bill");
// result: ["Bill Murray", "Bill Clinton"]
这等效于
[QStringList]($docs-qstringlist.html) result;
foreach (const [QString]($docs-qstring.html) &str, list) {
if (str.contains("Bill"))
result += str;
}
See also contains( ) 。
QStringList QStringList.filter (self, QRegExp rx)
这是一个重载函数。
返回所有匹配正则表达式的字符串列表rx。
QString QStringList.first (self)
int QStringList.indexOf (self, QString value, int from = 0)
返回的第一个精确匹配的索引位置rx在列表中,向前搜索从索引位置from。返回-1,如果没有项目匹配。
默认情况下,这个功能是区分大小写的。
See also lastIndexOf( )contains()和QRegExp.exactMatch( ) 。
int QStringList.indexOf (self, QRegExp rx, int from = 0)
返回第一次出现的索引位置value在列表中,向前搜索从索引位置from。返回-1,如果没有项目匹配。
See also lastIndexOf( )contains()和QList.indexOf( ) 。
QStringList.insert (self, int i, QString str)
bool QStringList.isEmpty (self)
QString QStringList.join (self, QString sep)
加入所有的字符串列表的字符串与由给定的分隔每个元素的单个字符串separator(可以是空字符串) 。
See also QString.split( ) 。
QString QStringList.last (self)
int QStringList.lastIndexOf (self, QString value, int from = -1)
返回的最后一个精确匹配的索引位置rx在列表中,从索引位置向后搜索from。如果from为-1 (默认值) ,该搜索从最后一个项目。返回-1,如果没有项目匹配。
默认情况下,这个功能是区分大小写的。
See also indexOf( )contains()和QRegExp.exactMatch( ) 。
int QStringList.lastIndexOf (self, QRegExp rx, int from = -1)
返回最后一次出现的索引位置value在列表中,从索引位置向后搜索from。如果from为-1 (默认值) ,该搜索从最后一个项目。返回-1,如果没有项目匹配。
默认情况下,这个功能是区分大小写的。
See also indexOf()和QList.lastIndexOf( ) 。
QStringList QStringList.mid (self, int pos, int length = -1)
QStringList.move (self, int from, int to)
QStringList.prepend (self, QString str)
int QStringList.removeAll (self, QString str)
QStringList.removeAt (self, int i)
int QStringList.removeDuplicates (self)
此函数删除重复项列表。条目不必进行排序。他们将保留原来的顺序。
返回删除条目的数量。
此功能被引入Qt的4.5 。
QStringList.replace (self, int i, QString str)
QStringList QStringList.replaceInStrings (self, QString before, QString after, Qt.CaseSensitivity cs = Qt.CaseSensitive)
返回一个字符串列表,其中每个字符串发生了before文本与替换after文本的地方before文字被发现。该before文本匹配大小写敏感或不依赖于cs标志。
例如:
[QStringList]($docs-qstringlist.html) list;
list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings("a", "o");
// list == ["olpho", "beto", "gommo", "epsilon"]
See also QString.replace( ) 。
QStringList QStringList.replaceInStrings (self, QRegExp rx, QString after)
这是一个重载函数。
取代了正则表达式的每个实例rx在每个字符串列表的字符串,以after。返回一个引用的字符串列表。
例如:
[QStringList]($docs-qstringlist.html) list;
list << "alpha" << "beta" << "gamma" << "epsilon";
list.replaceInStrings([QRegExp]($docs-qregexp.html)("^a"), "o");
// list == ["olpha", "beta", "gamma", "epsilon"]
对于包含正则表达式capturing parentheses,出现的\1,\2,…,在after被替换为rx。帽( 1 ) ,rx。盖(2 ) , …
例如:
[QStringList]($docs-qstringlist.html) list;
list << "Bill Clinton" << "Murray, Bill";
list.replaceInStrings([QRegExp]($docs-qregexp.html)("^(.*), (.*)$"), "\\2 \\1");
// list == ["Bill Clinton", "Bill Murray"]
QStringList.sort (self)
按升序排列(敏感的情况下)的字符串列表。
使用Qt的进行排序qSort( )算法,该算法在运行linear-logarithmic time,即澳(n登录n) 。
如果你想以任意顺序的字符串进行排序,请考虑使用QMap类。例如,您可以使用QMap\u003cQString,QString\u003e创建一个不区分大小写的排序(例如,使用按键作为字符串的小写版本,并作为字符串值) ,或QMap\u003c整数,QString\u003e由一些整数索引的字符串进行排序。
See also qSort( ) 。
QStringList.swap (self, int i, int j)
QString QStringList.takeAt (self, int i)
QString QStringList.takeFirst (self)
QString QStringList.takeLast (self)
QStringList QStringList.__add__ (self, QStringList other)
int QStringList.__contains__ (self, QString str)
QStringList.__delitem__ (self, int i)
QStringList.__delitem__ (self, slice slice)
bool QStringList.__eq__ (self, QStringList other)
QString QStringList.__getitem__ (self, int i)
QStringList QStringList.__getitem__ (self, slice slice)
QStringList QStringList.__iadd__ (self, QStringList other)
QStringList QStringList.__iadd__ (self, QString value)
QStringList QStringList.__imul__ (self, int by)
QStringList.__len__ (self)
QStringList QStringList.__lshift__ (self, QString str)
QStringList QStringList.__lshift__ (self, QStringList l)
QStringList QStringList.__mul__ (self, int by)
bool QStringList.__ne__ (self, QStringList other)
QStringList.__setitem__ (self, int i, QString str)
QStringList.__setitem__ (self, slice slice, QStringList list)