一个函数怎么返回一个QStringList
展开全部
QStringList类是QList的派生类,是字符串的列表类。它是一个非常有用的类,在处理字符串时使用QStringList,有时能事半功倍。
QStringList可以使用QList的所有方法,如:append(), prepend(), insert(), replace(), removeAll(), removeAt(), removeFirst(), removeLast(), and removeOne()。
示例:
[cpp] view plain copy
#include <QStringList>
#include <QTextStream>
static QTextStream cout(stdout, QIODevice::WriteOnly);
int main(int argc, char *argv[])
{
QString str = "1,2,3,4,5,6,7,8,9";
QStringList strList;
strList = str.split(",");
cout << "String list item count: " << strList.size() << endl;
for(int i = 0; i < strList.size(); i++)
cout << i + 1 << ":" << strList[i] << endl;
QString str2;
str2 = strList.join(",");
cout << str2 << endl;
return 0;
}
QStringList可以使用QList的所有方法,如:append(), prepend(), insert(), replace(), removeAll(), removeAt(), removeFirst(), removeLast(), and removeOne()。
示例:
[cpp] view plain copy
#include <QStringList>
#include <QTextStream>
static QTextStream cout(stdout, QIODevice::WriteOnly);
int main(int argc, char *argv[])
{
QString str = "1,2,3,4,5,6,7,8,9";
QStringList strList;
strList = str.split(",");
cout << "String list item count: " << strList.size() << endl;
for(int i = 0; i < strList.size(); i++)
cout << i + 1 << ":" << strList[i] << endl;
QString str2;
str2 = strList.join(",");
cout << str2 << endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询