View Full Version : adding new QChart in a QChartView

24th April 2017, 19:58
Hello. I'm trying to redraw chart with a new data and delete previous chart.
So here is my code.

QChart *oldSignalData = signalView->chart();

signalData = new QChart();

if(NULL != oldSignalData){
delete oldSignalData;

But when i putting a new QChart on a same QChartView - it fails with a message "Can not find axis on the chart."
This code works fine if i comment "delete oldSignalData;" string, but it causes memory leaks. What is the correct
way to delete previous chart and do not crush QChartView? Thanks.
Qt version - 5.8.0.

30th August 2019, 21:39

I know its an old thread but I am having the same problem. Also using basically the same code.

30th August 2019, 23:40
The error is likely because the view needs the event loop to run so it can clean up things from the old chart and initialize from the new one. But by calling delete on the old chart instance, you pull the rug out from under it.

Try replacing "delete oldSignalData" with "oldSignalData->deleteLater()". This will result in the old instance being deleted, but not until the event loop has had a chance to run.

7th September 2019, 16:02
@W1bowo (and all of the other names you are posting under): STOP DOING THIS. I have reported you as a troll.

If you want to thank someone for a useful post, use the "Thanks" button. DO NOT quote a part of a post and add a +1. It's trolling and is not making any useful contribution to the forum.