I am student programmer and I am using Qt to develop a GUI interface for work and Im having trouble figuring out how I should make this this import function work. A bit of programmers writers block if you will. SO far I have this for code:
void InjectionLocationsDialogExpanded::importCSVFile()
{
QString fileName = QFileDialog::getOpenFileName(this, ("Open File"), "/home", ("csv File(*.csv)"));
QString data;
QFile importedCSV(fileName);
QStringList rowOfData;
QStringList rowData;
int tempint = 0;
data.clear();
rowOfData.clear();
rowData.clear();
if (importedCSV.open(QFile::ReadOnly))
{
data = importedCSV.readAll();
rowOfData = data.split("\n");
rowData = data.split(";");
importedCSV.close();
}
qDebug() << data;
for (int x = 0; x < rowOfData.size(); x++)
{
for (int y = 0; y < ui->tableWidgetInjectionLocationsExpandedDialog->columnCount(); y++)
{
ui->tableWidgetInjectionLocationsExpandedDialog->item(x,y)->setText(rowData[]);
}
}
}
The issue here is that I don't know how to get the settext of each item in the table to reference the next item in the rowData QStringList. I need to increment by one location but I cant use a int++ because that will eventually look for a item in the QStringList that doesn't exist and cause a segmentation fault. I also cant use a for loop to cap the number I need in the location field here because of the current for loops structure. I just cant think of a good strategy for to approach this on. Please only leave constructive comments as I am only interested in learning or accomplishing this task. Thanks for reading!