how i can identify and read the columns of a csv file ?
-
@JonB @KroMignon @jsulm @J-Hilk
thank you for your answer I was able to solve the problem with
coordXList.append (line.split (','). at (0));
coordYList.append (line.split (','). at (1));
but I would like to put these values in a curve using the Qchart
I tried with
QLineSeries * series = new QLineSeries ();
series-> append (coordXList, coordYList);
but I got an error : no matching membre function for call to append
can you help me please@julie546 said in how i can identify and read the columns of a csv file ?:
thank you for your answer I was able to solve the problem with
coordXList.append (line.split (','). at (0));
coordYList.append (line.split (','). at (1));This is a dangerous and no effective way to do!
line.split(',')
may return an emptyQStringList
, soline.split (','). at(0)
will crash your application.
And why splitting twice?I would do it like this:
const auto parts = line.split (','); if(parts.size() >= 2) { coordXList.append(parts.at(0)); coordYList.append(parts.at(1)); }
but I would like to put these values in a curve using the Qchart
I tried with
QLineSeries * series = new QLineSeries ();
series-> append (coordXList, coordYList);
but I got an error : no matching membre function for call to append
can you help me pleaseHave you read
QLineSeries::append()
documentation??
There is not overload forQLineSeries::append(QStringList, QStringList)
! -
@julie546 thats not how programming works.
I assume
coordXList
andcoordYList
are string lists ?than you may, and I emphasise may, get away with:
QLineSeries * series = new QLineSeries (); for(int i{0}, j{qMin(coordXList.size(), coordYList.size())}; i<j; i++){ series-> append (coordXList.at(i).toFloat(), coordYList.at(i).toFloat()); }
-
@julie546 thats not how programming works.
I assume
coordXList
andcoordYList
are string lists ?than you may, and I emphasise may, get away with:
QLineSeries * series = new QLineSeries (); for(int i{0}, j{qMin(coordXList.size(), coordYList.size())}; i<j; i++){ series-> append (coordXList.at(i).toFloat(), coordYList.at(i).toFloat()); }
@J-Hilk yes here is my output ("Y", "0.170138", "0.161089", "0.15901", "0.157898", "0.159706", "0.162481", "0.167204", "0.172876", "0.169802", "0.1677",.....................)
theres an error with series-> append (coordXList.at(i).toFloat(), coordYList.toFloat());
no member named toFloat in QStringList
@KroMignon @J-Hilk can you help me please I am a beginner c ++ I am a student in mechanics but I need qt for my end of study internship -
@J-Hilk yes here is my output ("Y", "0.170138", "0.161089", "0.15901", "0.157898", "0.159706", "0.162481", "0.167204", "0.172876", "0.169802", "0.1677",.....................)
theres an error with series-> append (coordXList.at(i).toFloat(), coordYList.toFloat());
no member named toFloat in QStringList
@KroMignon @J-Hilk can you help me please I am a beginner c ++ I am a student in mechanics but I need qt for my end of study internship@julie546 said in how i can identify and read the columns of a csv file ?:
no member named toFloat in QStringList
typo on my side, fixed it, but you should be able to fix that as well
-
@J-Hilk yes here is my output ("Y", "0.170138", "0.161089", "0.15901", "0.157898", "0.159706", "0.162481", "0.167204", "0.172876", "0.169802", "0.1677",.....................)
theres an error with series-> append (coordXList.at(i).toFloat(), coordYList.toFloat());
no member named toFloat in QStringList
@KroMignon @J-Hilk can you help me please I am a beginner c ++ I am a student in mechanics but I need qt for my end of study internship@julie546 said in how i can identify and read the columns of a csv file ?:
can you help me please I am a beginner c ++ I am a student in mechanics but I need qt for my end of study internship
We have all started as beginner. I have studied electronics, not informatics, so I understand well your problem ;)
The easiest way to create the QLineSeries, is to do it while parsing:
QLineSeries * series = new QLineSeries(); while (!filelidar.atEnd()) { QString line = filelidar.readLine(); const auto parts = line.split (','); if(parts.size() >= 2) { bool ok; qreal x = parts.at(0).toFloat(&ok); if(!ok) continue; qreal y = parts.at(1).toFloat(&ok); if(!ok) continue; series->append(x, y); } }
-
@julie546 said in how i can identify and read the columns of a csv file ?:
can you help me please I am a beginner c ++ I am a student in mechanics but I need qt for my end of study internship
We have all started as beginner. I have studied electronics, not informatics, so I understand well your problem ;)
The easiest way to create the QLineSeries, is to do it while parsing:
QLineSeries * series = new QLineSeries(); while (!filelidar.atEnd()) { QString line = filelidar.readLine(); const auto parts = line.split (','); if(parts.size() >= 2) { bool ok; qreal x = parts.at(0).toFloat(&ok); if(!ok) continue; qreal y = parts.at(1).toFloat(&ok); if(!ok) continue; series->append(x, y); } }
@KroMignon yes it's really difficult to work in a field that you don't study
thank you for your answer I tried like that but I still have an empty curveif (!filelidar.open(QFile::ReadOnly | QFile::Text) ) {
qDebug() << "File not exists";
} else {QLineSeries * series = new QLineSeries(); while (!filelidar.atEnd()) { QString line = filelidar.readLine(); const auto parts = line.split (','); if(parts.size() >= 2) { bool ok; qreal x = parts.at(0).toFloat(&ok); if(!ok) continue; qreal y = parts.at(1).toFloat(&ok); if(!ok) continue; series->append(x, y); } } QChart *chart = new QChart(); chart->legend()->hide(); chart->addSeries(series); chart->createDefaultAxes(); chart->setTitle("Lidar tg15"); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); QMainWindow window; window.setCentralWidget(chartView); window.resize(1000, 1000); window.show(); /
}
} -
@KroMignon yes it's really difficult to work in a field that you don't study
thank you for your answer I tried like that but I still have an empty curveif (!filelidar.open(QFile::ReadOnly | QFile::Text) ) {
qDebug() << "File not exists";
} else {QLineSeries * series = new QLineSeries(); while (!filelidar.atEnd()) { QString line = filelidar.readLine(); const auto parts = line.split (','); if(parts.size() >= 2) { bool ok; qreal x = parts.at(0).toFloat(&ok); if(!ok) continue; qreal y = parts.at(1).toFloat(&ok); if(!ok) continue; series->append(x, y); } } QChart *chart = new QChart(); chart->legend()->hide(); chart->addSeries(series); chart->createDefaultAxes(); chart->setTitle("Lidar tg15"); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); QMainWindow window; window.setCentralWidget(chartView); window.resize(1000, 1000); window.show(); /
}
}@julie546 said in how i can identify and read the columns of a csv file ?:
qreal x = parts.at(0).toFloat(&ok);
if(!ok)
continue;
qreal y = parts.at(1).toFloat(&ok);Print the values for
x
andy
and check if these are the values from your file.
The code from @KroMignon doesn't look wrong. -
@julie546 said in how i can identify and read the columns of a csv file ?:
qreal x = parts.at(0).toFloat(&ok);
if(!ok)
continue;
qreal y = parts.at(1).toFloat(&ok);Print the values for
x
andy
and check if these are the values from your file.
The code from @KroMignon doesn't look wrong. -
@Pl45m4 @KroMignon yes I have checked I have the right values now I have a graph but it is not the same that I do with the csv file, I cannot find the same graph, what do you think please ?
-
@julie546 said in how i can identify and read the columns of a csv file ?:
but it is not the same that I do with the csv file,
What do you mean with not the same?
@KroMignon this is what I found with qt
and this is what I have to find
despite I made qDebug () << x;
qDebug () << y;
and I found the same values with csv file -
@KroMignon this is what I found with qt
and this is what I have to find
despite I made qDebug () << x;
qDebug () << y;
and I found the same values with csv file -
@julie546
Hi
If you look closely they are the same.
Its just you are using QLineSeries which draws lines between the points so
that why it looks differernt.Maybe the scatter type can be used
https://doc.qt.io/qt-5/qtcharts-scatterchart-example.htmlinstead of the LineSeries.
-
@julie546
Hi
If you look closely they are the same.
Its just you are using QLineSeries which draws lines between the points so
that why it looks differernt.Maybe the scatter type can be used
https://doc.qt.io/qt-5/qtcharts-scatterchart-example.htmlinstead of the LineSeries.
-
@mrjj
thank you for your reply I have changed it but there are some missing points
QScatterSeries * series = new QScatterSeries;
series->setMarkerShape(QScatterSeries::MarkerShapeRectangle); -
@julie546
Well it does look more like it
so the question if those points go missing during reading or where they go.What does the draw correct looking diagram ?
I mean what app ? -
@mrjj it is a 'lidar tg15' sensor
i did series->append(x, y);
qDebug() << y;
qDebug() << x;
and I found all the points -
@julie546
Ok but the right diagram you showed the picture of.
Did you hand draw this or did an app do it?since no points is missing im simply wondering if that data would allow the correct diagram at all.
-
@julie546
ok. and you used the same CSV file there ?and you compared the values we insert, value by value to make sure it reads as it should ?
I mean if it could not convert for some reason it would silently continue.
if(!ok) continue;
some of the points to the far right seems more out there than on correct diagram.
should be around 6.0 but is 6.8 -
@julie546
ok. and you used the same CSV file there ?and you compared the values we insert, value by value to make sure it reads as it should ?
I mean if it could not convert for some reason it would silently continue.
if(!ok) continue;
some of the points to the far right seems more out there than on correct diagram.
should be around 6.0 but is 6.8