QCustomPlot Discussion and Comments

Qcustomplot->replot() causes memory overflowReturn to overview

Hello,

I am struggling with suspected memory overflow due to Qcustomplot->replot(). I have 10 graphs added to 1 plot and they share common y-axis. Below is my code to update the graphs

void SPI::plotOnCommonAxis(unsigned int index, QList<double> signalValues)
{   
    for(int i =0; i<plots[startIndex]->plottableCount(); i++)
    {
        if(unSelectedGraphs.contains(i))
        {
            continue;
        }
       
        if((plots[startIndex]->plottableCount() - unSelectedGraphs.count()) == signalValues.count())
        {
          
            for(int j=0; j < spiSignalsSV.count(); j++)
            {
                if(spiSignalsSV[j]==checkbox[i]->text()) // this is just to make sure that incoming signal matches with the graph
                {
                    
                    signalText[i]->setText(QString::number(signalValues[j])); // this is just to update QLineEdit
                    plots[startIndex]->graph(i)->addData(index,signalValues[j]);      
                }
            }
        }

    }
    plots[startIndex]->rescaleAxes();
    plots[startIndex]->yAxis->scaleRange(1.1,plots[startIndex]->yAxis->range().center());
    plots[startIndex]->replot();
}

It works fine when I plot the data on individual plots with only one graph like 10 plots for 10 signals. It also works fine if I don't perform plots[startIndex]->replot()

Any suggestion/help would really be appreciated.

Thank you.

I have 5000 data points on each graph.

You mentioned you only have one plot, but I see that plots is actually an array or vector with multiple QCustomPlots, is that correct?
Note that every QCustomPlot will have its own pixel buffer and thus requires some overhead memory. For normal systems that's not a big issue, but depending on your platform limitations and the number of individual QCustomPlots you have in that array, it might add up.

Thanks for the replay.

Yes, plots is an array(QCustomPlot *plots[10]) but in above code I am updating only one plot out of an array.

In above code the startIndex is 5. So I would be plotting data of 10 graphs on plot number 5

Can someone please give some help/suggestion?

Thank you