kgdauaa88
14th October 2013, 02:24
So, I have a csv file where every row contains a timestamp (UTC) and a sensor reading. I have been trying to leverage the Qt libraries to aid me however, I have been having a lot of trouble. The following is my code
// Read files until one of the files ends
for (int i=0; i<noOfFiles; i++)
{
QStringList rowVec;
QString value,timestamp,row;
QDateTime timestampH;
while (!(*finVec[i]).eof())
{
string str;
getline(*(finVec[i]),str);
row = QString::fromLocal8Bit(str.c_str());
rowVec = row.split(",");
timestamp = rowVec.at(0);
value = rowVec.at(1);
timestampH = QDateTime::fromString(timestamp,"yyyy-MM-dd HH:mm:ss");
timestampH.setTimeSpec(Qt::UTC);
cout << timestampH.isNull() << endl;
}
}
The result of the code is always such that timestampH is NULL! I am 100% sure that the data in my csv file is the same exact format as "yyyy-MM-dd HH:mm:ss". In fact if I copy and paste a single timestamp into my code replacing the variable (QString timestamp) i dont get any problems. Can someone please help me on this I have tried everything the past 2 days and got no where
// Read files until one of the files ends
for (int i=0; i<noOfFiles; i++)
{
QStringList rowVec;
QString value,timestamp,row;
QDateTime timestampH;
while (!(*finVec[i]).eof())
{
string str;
getline(*(finVec[i]),str);
row = QString::fromLocal8Bit(str.c_str());
rowVec = row.split(",");
timestamp = rowVec.at(0);
value = rowVec.at(1);
timestampH = QDateTime::fromString(timestamp,"yyyy-MM-dd HH:mm:ss");
timestampH.setTimeSpec(Qt::UTC);
cout << timestampH.isNull() << endl;
}
}
The result of the code is always such that timestampH is NULL! I am 100% sure that the data in my csv file is the same exact format as "yyyy-MM-dd HH:mm:ss". In fact if I copy and paste a single timestamp into my code replacing the variable (QString timestamp) i dont get any problems. Can someone please help me on this I have tried everything the past 2 days and got no where