How to import a CSV file to a QTableWidget

不问归期 提交于 2019-12-04 19:27:29

First of all, you would need to take care of line endings. This means that your code might not be platform independent if you just check for "\n" in your CSV file.

If I get what you're trying to do, you would have to set the rowData within the for-loop. So, what I would do then :

rowOfData.clear();
rowData.clear();

if (importedCSV.open(QFile::ReadOnly))
{
    data = importedCSV.readAll();
    rowOfData = data.split("\n");
    importedCSV.close();
}

for (int x = 0; x < rowOfData.size(); x++)
{
    rowData = rowOfData.at(x).split(";");
    for (int y = 0; y < rowData.size(); y++)
    {
        ui->tableWidgetInjectionLocationsExpandedDialog->item(x,y)->setText(rowData[y]);
    }
}

I guess this should do it. Best regards.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!