Hello everyone,
I made a program that collects data from an Arduino
in x,y format in a listwidget. These x, y values ??must then be sent to the Qcustomplot and that's where there is a problem.
There is a comma between x and y. They arrive like that from the Arduino to be used in the Excel graph.
My problem is when collecting the data in the ui->customplot->graph(0)->setData(x,y) function;
I can't convert the data from the "QString(data)" to convert them
Here is the blocking part: (after ui->listwidget..)
void NetworkPlot::readData()
{
qDebug() <<"Serialport works"; // it's ok (control port com)
auto data = arduino->readAll(); // it's ok
ui
->listWidget
->addItem
(QString(data
));
// it's ok
if (parts.size() == 2) {
qDebug() << parts.at(1).toDouble() << parts.at(2).toDouble();
mag.append(x) = parts.at(1).toDouble();
num.append(y) = parts.at(2).toDouble();
QVector<double> mag;
QVector<double> num;
ui->customplot->graph(0)->setData(x,y);
ui->customplot->replot();
ui->customplot->update();
}
void NetworkPlot::readData()
{
qDebug() <<"Serialport works"; // it's ok (control port com)
auto data = arduino->readAll(); // it's ok
ui->listWidget->addItem(QString(data)); // it's ok
QString str = QString(data); // start of problem
QStringList parts = str.split(" ");
if (parts.size() == 2) {
qDebug() << parts.at(1).toDouble() << parts.at(2).toDouble();
mag.append(x) = parts.at(1).toDouble();
num.append(y) = parts.at(2).toDouble();
QVector<double> mag;
QVector<double> num;
ui->customplot->graph(0)->setData(x,y);
ui->customplot->replot();
ui->customplot->update();
}
To copy to clipboard, switch view to plain text mode
My first test;
void NetworkPlot::readData()
{
qDebug() <<"Serialport works"; //ok
auto data = arduino->readAll(); //ok
ui
->listWidget
->addItem
(QString(data
));
//ok QVector<double> x,y;
ui->customplot->graph(0)->setData(x,y);
ui->customplot->replot();
ui->customplot->update();
}
void NetworkPlot::readData()
{
qDebug() <<"Serialport works"; //ok
auto data = arduino->readAll(); //ok
ui->listWidget->addItem(QString(data)); //ok
QVector<double> x,y;
ui->customplot->graph(0)->setData(x,y);
ui->customplot->replot();
ui->customplot->update();
}
To copy to clipboard, switch view to plain text mode
There is a formatting that totally escapes me and I spent hours testing. This is my first application in C++ and I only have knowledge in basic and arduino but it is progressing.
I specify that I am French-speaking and I translate my request.
Thank you for your help
[IMG][/IMG]
Bookmarks