Important: Please read the Qt Code of Conduct -

I have trouble plotting multiple datapoints using QCPCurve

  • Hello!
    I would like to plot multiple datapoints to my widget using QCustomPlot.
    The graph they will resemble will have multiple y-Values assigned to the same x-value, which is why using "Graph" did not get me anyhwere.
    Initially, I defined a QVector whose values I plotted through


    However - as I said - this doesn't help me since I need to be able to manually control the order of connection of points.

    After research I learned that I need to use QCPCurve by defining:

    QCPCurve *newCurve = new QCPCurve(ui->plot->xAxis, ui->plot->yAxis); (1)
    ui->customPlot->addPlottable(this->newCurve); (2)

    Allegedly I should now be able to plot the points by using a QVector as I was used to do it using "Graph" by writing:
    this->newCurve->setData(x, y);

    The problem I have is that line (2) and (3) give me the the following error messages:

    'class QCustomPlot' has no member named 'addPlottable'; did you mean 'hasPlottable'?
    'class MainWindow' has no member named 'newCurve'
    unused variable 'new Curve' [-Wunused-variable]
    'class MainWindow' has no member named 'newCurve'

    Every thread I searched simply stated that I have to implement these three lines (1) (2) (3).
    I think that my problem lies in needing to define the Plottable for QCP or sth like that.
    I am a complete beginner and all these things do not say anything to me..

    I will attach my code below so you have more information, can anyone explain me what the nature of the problem is?

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        QCPCurve *newCurve = new QCPCurve(ui->plot->xAxis, ui->plot->yAxis);
         ui->plot->addPlottable (this->newCurve);
        delete ui;
    void MainWindow::on_btn_start_clicked()
    QVector<double> x(1),y(1);
    x[0] = 1;
    y[0] = 2;

    This is my mainwindow.cpp class.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    QCustomPlot is an independent project, you might want to check their forum for your issue.

  • Thank you for the information. I posted a thread there too now.
    If its ok I would leave this thread in case anyone can help..

Log in to reply