1
我正在创建一个名为getExcelFile()的函数来获取excel文件的内容并将其存储到结构数组中。首先我想读一行csv文件并使用分隔符,。然后,我想将内容添加到QStringList,并使用for循环遍历一个结构数组,并将内容添加到其中。一切工作正常,除了它说datalist.append((line.split(',')));帮助将不胜感激!QT解析CSV文件的内容并将其存储到结构数组中
void Widget::getExcelFile(){
//Name of the Qfile object.
//filename is the directory of the file once it has been selected in prompt
QFile thefile(filename);
//QStringList named datalist.
QStringList datalist;
//If the file is successfully open
if (thefile.open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug() << "File opened successfully";
while (!thefile.atEnd()){
QByteArray line = thefile.readLine();
datalist.append((line.split(',')));
}
}
qDebug() << datalist;
ui->textEdit->setPlainText(fileContent);
}
的可能重复:https://stackoverflow.com/questions/27318631/parsing-through-a-csv-file-in-qt – besc