QCustomPlot Discussion and Comments

Trouble with passing a value from lineedit to a GraphReturn to overview

Hi All,

I am new to Qt and started exploring some of its features. I am stuck in a problem. In the form.ui I have a lineedit, a push button and a widget (promoted to QCustomPlot). My requirement is when a value is entered in lineedit and after push button is pressed, it should create a line on the graph. My code is -
void Form:on_refForceValueButton_clicked()
{
float ref_force_value = ui->lineEdit->text().toFloat(); // to read the value entered in line edit in form.ui

// to take the value of lineedit and pass on to y co-ordinate of graph to have a straight line
QCPItemLine *lineX = new QCPItemLine(ui->customPlotX);
lineX->start->setCoords(0,ref_force_value);
lineX->end->setCoords(1000000,ref_force_value);
lineX->setPen(QPen(Qt::black));


if (ref_force_value>0)
{
QString msg = "Reference Force Value is set to " + QString::number(ref_force_value) + "mN."; // to combine string and float

QMessageBox::information(this, "Reference Force Value", msg); // to pop-up window displaying message when button is clicked
}
}

As you can see from the code I have a widget (promoted to QCustomPlot). When I enter the value in lineedit and click the button it works well with pop-up window and it displays the message but it doesn't pass the value entered in lineedit on to the graph. Can anyone please guide me on my code. I am using Qt5.8 on Windows 10 with MinGW compiler.

Thank you for your time and knowledge.

you need to call ui->customPlotX->replot() after adding the line.