admkrk
14th May 2017, 03:06
I have this pretty much working and am storing the data in a QList<QString>. When I print it out with qDebug() though, the strings have additional quotes, along with escaped quotes. This makes me think I need to erase the original quotes, when I split the strings?
QTextStream bomIn(&bomFile);
QList<QStringList> bomData;
while(!bomIn.atEnd())
{
QString line = bomIn.readLine();
QStringList rowList = line.split(';');
bomData.append(rowList);
}
bomFile.close();
// for testing
QStringList list;
QString string;
foreach (list, bomData)
{
foreach(string, list)
{
qDebug() << string;
}
}
// end testing
I also need to display the data in a QTableView, and use one of the columns to run queries in my database. Maybe the quote issue will go away in the view?
Subclassing QAbstractItemModel looks like the best way to go, but I am having trouble figuring out a couple things. From the examples I have seen, it looks like I need to pass my QList to the model, in order to implement rowCount(), which should be size() - 1, since the first is the headers, I think. I then need a way to set the header data, somehow, the examples were all hard coded. The CSV files could be coming from different sources, and have different headers so that is not an option. I might be able to think of a way to loop through the first QStringList and do it, but am not sure if that is the way to go? I think I figured out the last question I had, while I was writing this.
QTextStream bomIn(&bomFile);
QList<QStringList> bomData;
while(!bomIn.atEnd())
{
QString line = bomIn.readLine();
QStringList rowList = line.split(';');
bomData.append(rowList);
}
bomFile.close();
// for testing
QStringList list;
QString string;
foreach (list, bomData)
{
foreach(string, list)
{
qDebug() << string;
}
}
// end testing
I also need to display the data in a QTableView, and use one of the columns to run queries in my database. Maybe the quote issue will go away in the view?
Subclassing QAbstractItemModel looks like the best way to go, but I am having trouble figuring out a couple things. From the examples I have seen, it looks like I need to pass my QList to the model, in order to implement rowCount(), which should be size() - 1, since the first is the headers, I think. I then need a way to set the header data, somehow, the examples were all hard coded. The CSV files could be coming from different sources, and have different headers so that is not an option. I might be able to think of a way to loop through the first QStringList and do it, but am not sure if that is the way to go? I think I figured out the last question I had, while I was writing this.