PDA

View Full Version : adding new QChart in a QChartView



zemlemer
24th April 2017, 20: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();
signalData->legend()->hide();
signalData->addSeries(signalSamples);
signalData->createDefaultAxes();
signalData->setTitle(comboTests->currentText());
signalView->setChart(signalData);

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.

bandito
30th August 2019, 22:39
<BUMP>

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

d_stranz
31st August 2019, 00: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.

d_stranz
7th September 2019, 17: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.