1

in my csv file values decimalpoint is a comma. So I can open the csv in Excel and Excel won't format my values to date.

When I open the file in my own software and convert the String to float, the values can't be read: bool ok returns false.

QTextStream stream(&file);
QLocale locale = QLocale();
qDebug() << locale.decimalPoint(); //returns ","
stream.setLocale(locale);

QString LineFromFile = stream.readLine();
QStringList DataFromRow = LineFromFile.split(";");

QList<float> values;
for (int i = 0; i < ValuesCnt; ++i){
   values.append(DataFromRow.at(i).toFloat());
   qDebug() << DataFromRow.at(i) << values.at(i);   //returns e.g.: "700,1" 0
}
Cat
  • 11
  • 1
  • 2
  • Be sure, that `DataFromRow.at(i)` contain no spaces or other separators. You may try next: `DataFromRow.at(i).trimmed().toFloat()`. – Dmitry Sazonov Feb 01 '16 at 13:58

1 Answers1

0

You set the locale for the stream, this does not work presumably, because I don't think that the locale is transferred to the element of the QStringList object DataFromRow. You have to set the locale to them. However, I would prefer using the following:

for (int i = 0; i < ValuesCnt; ++i){
  values.append(locale.toFloat( DataFromRow.at(i)));

See qt's documentation of QLocale::toDouble()

MarkusParker
  • 1,264
  • 2
  • 17
  • 35
  • Thank You! This is what i was looking for. When I save the file, I have to set the locale to the stream, so the values will be displayed with a comma. – Cat Feb 03 '16 at 06:42