QCustomPlot Discussion and Comments

unsuccessful QCPItemLine object deleteReturn to overview

Hello,
I'm trying to create and delete a dynamic amount of QCPItemLine objects.

    if(!lineVector.isEmpty())
    {
        for(int i = 0; i < lineVector.size(); i++)
        {
            delete lineVector.at(i);
        }
        lineVector.clear();
        ui->myPlot->replot();
    }
    for(int i = 0; i < getCurrentParser()->getKeyEvents().TNKE; i++)
    {
        double x = convert.time100psToSamples(getCurrentParser()->getEvent().EPT.at(i),
                                              getCurrentParser()->getPulse().DS.at(0));
        invisTracer->setGraphKey(x);
        ui->myPlot->layer("overlay")->replot();
        double y = invisTracer->position->value();
        lineVector.append(new QCPItemLine(ui->myPlot));
        lineVector.at(i)->start->setCoords(x, y+5);
        lineVector.at(i)->end->setCoords(x, y-5);
        lineVector.at(i)->setPen(QPen(QColor(0, 128, 0)));
    }

    ui->myPlot->replot();

but after cycling this code snippet a few times this warning pops up:
bool QCustomPlot::registerItem(QCPAbstractItem*) item already added to this QCustomPlot: 10705936
after calling this linelineVector.append(new QCPItemLine(ui->myPlot));
Does it mean that QCPItemLine objects weren't completely deleted?

As stated in the documentation
http://www.qcustomplot.com/documentation/classQCPItemLine.html#a17804b7f64961c6accf25b61e85142e3

QCP takes ownership of the item, so you're not allowed to delete it. Essentially you're corrupting memory.

Use QCustomPlot::removeItem to remove an item.