QT QStringList 与 QString 相互转换
程序员文章站
2024-03-17 18:58:28
...
QStringList 转 QString
QStringList listemp;
listemp << "Apple" << "Grape" << "Orange" << "Banana";
QString str = listemp.join(",");
qDebug() << "\r\nstr:" << str;
//输出结果如下
//str: "Apple,Grape,Orange,Banana"
QString转 QStringList
QString strtmp = "apple:5.99;grape:12.5;orange:6.99";
QStringList fruits = strtmp.split(";");
qDebug() << "\r\nfruits:" << fruits;
//fruits: ("apple:5.99", "grape:12.5", "orange:6.99")
//
for(int i=0; i < fruits.size(); i++)
{
QStringList fruit = fruits[i].split((":"));
qDebug() << "fruit:" << fruit;
/*
fruit: ("apple", "5.99")
fruit: ("grape", "12.5")
fruit: ("orange", "6.99")
*/
}
上一篇: STL系列(二) 二分查找
下一篇: jQuery基础一