COM+QCustomPlot problem is QStringList[].toDouble()
-
hi. i am a newbie in QT. I need ur help to solve my problem.
my problem is : i can't read value of "giatri" when i use systax: giatri=QString(bufferSplit[0]).toDouble();
i still read bufferSpilt[0].
here my code:
void MainWindow::serialport_read()
{QStringList bufferSplit = data_string.split("\n"); if(bufferSplit.length()<2) { buffer=serialPort->readAll(); data_string+=QString::fromStdString(buffer.toStdString()); } else { ui->pteReceive->insertPlainText(bufferSplit[0]); // show data read ok! eg: 96,80,94 giatri=QString(bufferSplit[0]).toDouble();// not working //giatri++; time=time+1; addPoint(time,giatri); plot(); data_string=""; }
}
and my result :
thank ur help! -
@banhmisua said in COM+QCustomPlot problem is QStringList[].toDouble():
my problem is : i can't read value of "giatri" when i use systax: giatri=QString(bufferSplit[0]).toDouble();
i still read bufferSpilt[0].Can you please explain better?
Of course you read bufferSpilt[0] - because that is what you wrote!
So, what do you want to do? -
@banhmisua said in COM+QCustomPlot problem is QStringList[].toDouble():
so i want convert bufferSplit[0] to double giatri and plot it. that's all.
But you do it already...
giatri=QString(bufferSplit[0]).toDouble()
What's the content of
bufferSplit[0]
? Please addqDebug() << "bufferSplit[0]:" << bufferSplit[0]
and post it here.
-
@Christian-Ehrlicher . i did as u said. and i have problem.
When i DEBUG step by step, everything is right!
bufferSplit[0]: "82"
bufferSplit[0]: "82"
bufferSplit[0]: "82"
bufferSplit[0]: "82"
bufferSplit[0]: "240"
bufferSplit[0]: "82"but when i RUN. i got:
bufferSplit[0]: "82"
bufferSplit[0]: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000082"
bufferSplit[0]: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000082"
bufferSplit[0]: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000082"
So what is problem here? can u tell me how solve it?
thank u very much. -
I don't see a problem here except that sometimes you get 0 as value which you have to handle. We don't know what 0 means in your context.