Results 1 to 4 of 4

Thread: adding new QChart in a QChartView

  1. #1
    Join Date
    Apr 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default adding new QChart in a QChartView

    Hello. I'm trying to redraw chart with a new data and delete previous chart.
    So here is my code.

    Qt Code:
    1. QChart *oldSignalData = signalView->chart();
    2.  
    3. signalData = new QChart();
    4. signalData->legend()->hide();
    5. signalData->addSeries(signalSamples);
    6. signalData->createDefaultAxes();
    7. signalData->setTitle(comboTests->currentText());
    8. signalView->setChart(signalData);
    9.  
    10. if(NULL != oldSignalData){
    11. delete oldSignalData;
    12. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Mar 2016
    Posts
    15
    Thanks
    2
    Qt products
    Qt5

    Default Re: adding new QChart in a QChartView

    <BUMP>

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

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,172
    Thanks
    235
    Thanked 662 Times in 652 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: adding new QChart in a QChartView

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,172
    Thanks
    235
    Thanked 662 Times in 652 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: adding new QChart in a QChartView

    @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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. qchart hide legend for part of series
    By marrierius in forum Newbie
    Replies: 2
    Last Post: 14th March 2017, 14:40
  2. Dynamically updating QChart
    By nbkhwjm in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2017, 18:06
  3. contextMenuEvent works partially in QChart
    By marrierius in forum Newbie
    Replies: 0
    Last Post: 16th December 2016, 19:48
  4. Problem getting QChartView to display
    By derrickbj in forum Qt Programming
    Replies: 5
    Last Post: 20th September 2016, 17:55
  5. How to do QChartView delegate like QTableView item delegate
    By malleeswarareddy.s in forum Qt Programming
    Replies: 0
    Last Post: 16th September 2015, 12:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.