QCustomPlot Discussion and Comments

removePlottables context menu crashReturn to overview

If I right click on the legend to generate the context menu, select remove a selected plot from the context menu my program crashes.

context menu call to remove selected plot:

 void my_plot::selectedPlot_remove()
{
    if (ui->customPlot->selectedPlottables().size() > 0)
    {
        ui->customPlot->removePlottable(ui->customPlot->selectedPlottables().first());
    }
    ui->customPlot->replot();
}

This only happens if the initial right click to generate the context menu was on the legend, it works perfectly in every other place.

Also, if I select remove all I have no issues

context menu call to remove all plots:

void my_plot::removeAll()
{
    ui->customPlot->clearGraphs();
    ui->customPlot->clearPlottables();
    ui->customPlot->replot();
}

I do not have the crash when using the 1.0.0-beta
I have had the crash with every version since.
I had forgot about this issue as I didn't really have any reason to update past 1.0.0.
Now that the 1.2 beta adaptive sampling works so well I need to figure this out!

Error is Segmentation Fault in the mouseMoveEvent function

void QCustomPlot::mouseMoveEvent(QMouseEvent *event)
{
  emit mouseMove(event);

  // call event of affected layout element:
  if (mMouseEventElement)
    mMouseEventElement->mouseMoveEvent(event); <- Line which the code dies at
  
  QWidget::mouseMoveEvent(event);
}

Yep, spotted it and working on it already. Fixed version should be up shortly.

More testing:
The right click must be on the legend object that is being removed to cause the crash.
As long and the mouse is not moved after the plottable is removed the program will not crash.

Perfect. Thank you.

It's uploaded and I've edited the news post to contain the new links. Thanks for reporting this bug!