QCustomPlot Discussion and Comments

unable to plot in functionReturn to overview

Hello, I'm unable to plot whenever I call a function, but I am able to plot and add a graph in main. This is qmake and mainwindow widget. Whenever I plot in a function I get the error message.

"QCPGraph* QCustomPlot::graph(int) const index out of bounds: 2"

function in .cpp

void MainWindow::settt(QVector<double> x,QVector<double> y)
{
   ui->customplot->addGraph();
   ui->customplot->graph(1)->setName("gauss");
   ui->customplot->yAxis->setRange(-3000,4000);
   ui->customplot->xAxis->setRange(-3000,2000);
   ui->customplot->graph(1)->setData(x,y);
   ui->customplot->rescaleAxes();
   ui->customplot->replot();
   ui->customplot->update();
}

in .h

void settt(QVector<double> x, QVector<double> y);


could it be with the way the function is called?, whenever i plot in main, i get results and I am able to plot multiple data sets but with functions its problematic.

thank you.


nevermind, the problem was calling it in the wrong spot in main,

ui->customplot->addGraph(),use ui->customplot->graph(0)