QStringList
时间: 2024-05-13 22:21:06 浏览: 105
QT QStringList 用法.docx
5星 · 资源好评率100%
QStringList is a class in Qt that is used to manipulate lists of strings. It is a part of the QtCore module and provides many useful functions for working with string lists.
Some of the functions provided by the QStringList class include:
- append(): adds a new string to the end of the list
- prepend(): adds a new string to the beginning of the list
- removeFirst(): removes the first string in the list
- removeLast(): removes the last string in the list
- join(): joins all the strings in the list into a single string with a separator
- split(): splits a string into a list of strings based on a separator
- sort(): sorts the list of strings in alphabetical order
- contains(): checks if a given string is present in the list
Example:
```
QStringList fruits;
fruits.append("apple");
fruits.append("banana");
fruits.append("orange");
QStringList vegetables;
vegetables << "carrot" << "potato" << "cucumber";
QStringList allItems = fruits + vegetables;
qDebug() << allItems.join(", "); // Output: "apple, banana, orange, carrot, potato, cucumber"
allItems.sort();
qDebug() << allItems; // Output: "apple", "banana", "carrot", "cucumber", "orange", "potato"
```
阅读全文