//创建一个path路径、 路径记录着创建文件的路径 csv文件
QString path = QFileDialog::getSaveFileName(this,"save","../","CSV(*.csv)");
//如果 如果创建路径成功
if(path.isEmpty() == false)
{
//关联文件名字
file.setFileName(path);
//只写模式打开
bool isOk = file.open(QIODevice::WriteOnly);
if(isOk == true)
{
lines << "class,name,age,score,teacher " << "3,XiaoDong,12,97,Joy " << "4,XiaoYao,12,99,Martin ";
for (int i = 0; i < lines.size(); i++)
{
//写数据到csv中
file.write(lines[i].toLocal8Bit());
};
}
//关闭
file.close();
}