Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Deleting QChart Causes 30+ Second Application Hang!
Forum Updated to NodeBB v4.3 + New Features

Deleting QChart Causes 30+ Second Application Hang!

Scheduled Pinned Locked Moved Unsolved General and Desktop
51 Posts 5 Posters 4.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J JonB
    3 Mar 2025, 20:18

    @FleetingMemory
    So it should be reproducible with half a million random points across, say, 10 series? I think it keeps them as a QMap, I'm not sure whether 30 seconds is to be expected for deleting them all, it does sound a bit long. As @JoeCFD says, you might have to thin your plotted points. If you want to investigate further, try creating the line series and then deleting them without even adding them to the chart, is that similar time?

    F Offline
    F Offline
    FleetingMemory
    wrote on 3 Mar 2025, 21:13 last edited by FleetingMemory 3 Mar 2025, 21:30
    #7

    @JonB I tried storing all the series* in a QMap<int, series*> after building them instead of the chart. I then for-looped the Map and deleted the series* within (as well as the map itself). This deletion process took less than 1 second. So the issue is when clearing/deleting the chart

    My computer is running 12/24T Xeon, with 128gb ddr4 memory (so it's not my system....)

    Update - If I still attach to the chart and build the QMap above, and then loop through and delete it again takes ~30+ seconds to delete all the series from memory. There seems to be an issue with deleting them after they are added to the QChart...

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FleetingMemory
      wrote on 4 Mar 2025, 21:53 last edited by FleetingMemory 3 Apr 2025, 21:53
      #8

      So I have done a little digging. It seems no matter what I do, whether I delete all series or delete the chart, as it deletes, the chart loops through its update/repaint method removing one series at a time. I think these function calls are what is slowing it down. It needs to be updated so that it does not call repaint or loop through update when delete is called. I think this is a bug?

      @JonB @JoeCFD

      J J 2 Replies Last reply 5 Mar 2025, 12:10
      0
      • F FleetingMemory
        4 Mar 2025, 21:53

        So I have done a little digging. It seems no matter what I do, whether I delete all series or delete the chart, as it deletes, the chart loops through its update/repaint method removing one series at a time. I think these function calls are what is slowing it down. It needs to be updated so that it does not call repaint or loop through update when delete is called. I think this is a bug?

        @JonB @JoeCFD

        J Online
        J Online
        JonB
        wrote on 5 Mar 2025, 12:10 last edited by JonB 3 May 2025, 12:14
        #9

        @FleetingMemory
        Well I don't find anything like you do. Here is a sample I think you should try:

        #ifndef WIDGET_H
        #define WIDGET_H
        
        #include <QtCharts>
        #include <QWidget>
        
        class Widget : public QWidget
        {
            Q_OBJECT
        
        public:
            Widget(QWidget *parent = nullptr);
            ~Widget();
        
        private:
            QChart *chart;
            QChartView *chartView;
        
        private slots:
            void deleteChart();
        };
        #endif // WIDGET_H
        
        #include <QDebug>
        #include <QElapsedTimer>
        #include <QTimer>
        #include <QVBoxLayout>
        
        #include "widget.h"
        
        // using namespace QtCharts;
        
        Widget::Widget(QWidget *parent)
            : QWidget(parent)
        {
            setGeometry(100, 100, 800, 600);
            setLayout(new QVBoxLayout);
        
            this->chart = new QChart();
            this->chartView = new QChartView(chart, this);
            layout()->addWidget(chartView);
            chartView->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
        
            for (int i = 0; i < 10; i++)
            {
                QLineSeries* series = new QLineSeries();
                for (int x = 0; x < 50000; x++)
                    series->append(x, x * (i + 1));
                chart->addSeries(series);
            }
        
            QTimer::singleShot(2000, this, &Widget::deleteChart);
        }
        
        void Widget::deleteChart()
        {
            QElapsedTimer elapsed;
            qDebug() << "Starting to delete";
            elapsed.start();
            layout()->removeWidget(chartView);
            delete chart;
            chart = nullptr;
            delete chartView;
            chartView = nullptr;
            qDebug() << "Finished deleting" << elapsed.elapsed();
        }
        
        Widget::~Widget() {}
        

        500,000 points, 10 series. For me this takes 6 milliseconds to "delete", where you claim 30 seconds! Ubuntu 24.04, VirtualBox slow machine/not nearly as much memory as you, Qt 6.4.2 supplied with Ubuntu. How long does it take you?

        Possible it could be slow if compiled for Debug, though that is actually how I ran mine, you might check whether Release makes a huger difference?

        F 2 Replies Last reply 5 Mar 2025, 15:38
        1
        • F FleetingMemory
          4 Mar 2025, 21:53

          So I have done a little digging. It seems no matter what I do, whether I delete all series or delete the chart, as it deletes, the chart loops through its update/repaint method removing one series at a time. I think these function calls are what is slowing it down. It needs to be updated so that it does not call repaint or loop through update when delete is called. I think this is a bug?

          @JonB @JoeCFD

          J Offline
          J Offline
          JoeCFD
          wrote on 5 Mar 2025, 12:29 last edited by
          #10

          @FleetingMemory Is it possible to block qchart plotting while series are deleted. Do update of qchart after all series are cleared?

          J 1 Reply Last reply 5 Mar 2025, 12:44
          0
          • J JoeCFD
            5 Mar 2025, 12:29

            @FleetingMemory Is it possible to block qchart plotting while series are deleted. Do update of qchart after all series are cleared?

            J Online
            J Online
            JonB
            wrote on 5 Mar 2025, 12:44 last edited by
            #11

            @JoeCFD
            If you read OP's first post I am relying that he has tried all this sort of stuff. I just take his first two points and delete the chart view and chart, which he claims is slow.

            J 1 Reply Last reply 5 Mar 2025, 13:33
            0
            • J JonB
              5 Mar 2025, 12:44

              @JoeCFD
              If you read OP's first post I am relying that he has tried all this sort of stuff. I just take his first two points and delete the chart view and chart, which he claims is slow.

              J Offline
              J Offline
              JoeCFD
              wrote on 5 Mar 2025, 13:33 last edited by JoeCFD 3 May 2025, 13:39
              #12

              @JonB In his first post, He did

              deleting the QChart
              deleting the QChartView
              Hiding chart/chartview prior to deleting
              Removing all series prior to deleting  <===he might not have tried to block update of qchart in deletion of series. 
              running QCoreApplication::procesEvents() before/after delete
              

              His issue:
              as it deletes, the chart loops through its update/repaint method removing one series at a time.

              If he is able to block update of qchart while series are deleted, one final update may be ok. I do not use QChart (not free) and am not sure if it is doable.

              J 1 Reply Last reply 5 Mar 2025, 13:44
              0
              • J JoeCFD
                5 Mar 2025, 13:33

                @JonB In his first post, He did

                deleting the QChart
                deleting the QChartView
                Hiding chart/chartview prior to deleting
                Removing all series prior to deleting  <===he might not have tried to block update of qchart in deletion of series. 
                running QCoreApplication::procesEvents() before/after delete
                

                His issue:
                as it deletes, the chart loops through its update/repaint method removing one series at a time.

                If he is able to block update of qchart while series are deleted, one final update may be ok. I do not use QChart (not free) and am not sure if it is doable.

                J Online
                J Online
                JonB
                wrote on 5 Mar 2025, 13:44 last edited by
                #13

                @JoeCFD
                I'm still not with you. The first two lines says he deletes chart and view. I do no more or less than that in my code. It takes 6 milliseconds. He says it takes him 30 seconds. I don't know why or what other than mine he is doing or needs to do? (I checked my code with valgrind, no leaks reported.)

                J 1 Reply Last reply 5 Mar 2025, 13:48
                0
                • J JonB
                  5 Mar 2025, 13:44

                  @JoeCFD
                  I'm still not with you. The first two lines says he deletes chart and view. I do no more or less than that in my code. It takes 6 milliseconds. He says it takes him 30 seconds. I don't know why or what other than mine he is doing or needs to do? (I checked my code with valgrind, no leaks reported.)

                  J Offline
                  J Offline
                  JoeCFD
                  wrote on 5 Mar 2025, 13:48 last edited by
                  #14

                  @JonB Could be hardware related. I think he needs to try your code and see if he still has the same problem. If not, he has other issues in his code.

                  J 1 Reply Last reply 5 Mar 2025, 13:50
                  0
                  • J JoeCFD
                    5 Mar 2025, 13:48

                    @JonB Could be hardware related. I think he needs to try your code and see if he still has the same problem. If not, he has other issues in his code.

                    J Online
                    J Online
                    JonB
                    wrote on 5 Mar 2025, 13:50 last edited by
                    #15

                    @JoeCFD
                    I am hoping he will (a) try my code and see the time for him, (b) criticise my code if I have done anything wrong (like a leak) and then (c) compare against whatever else he is doing if different.

                    J 1 Reply Last reply 5 Mar 2025, 13:59
                    1
                    • J JonB
                      5 Mar 2025, 13:50

                      @JoeCFD
                      I am hoping he will (a) try my code and see the time for him, (b) criticise my code if I have done anything wrong (like a leak) and then (c) compare against whatever else he is doing if different.

                      J Offline
                      J Offline
                      JoeCFD
                      wrote on 5 Mar 2025, 13:59 last edited by
                      #16

                      @JonB If I were him, I would have tried your code already.

                      1 Reply Last reply
                      0
                      • J Online
                        J Online
                        JonB
                        wrote on 5 Mar 2025, 14:00 last edited by
                        #17

                        He may not be on same timezone/working/reading! Hopefully later.

                        J 1 Reply Last reply 5 Mar 2025, 14:00
                        0
                        • J JonB
                          5 Mar 2025, 14:00

                          He may not be on same timezone/working/reading! Hopefully later.

                          J Offline
                          J Offline
                          JoeCFD
                          wrote on 5 Mar 2025, 14:00 last edited by
                          #18

                          @JonB Likely.

                          1 Reply Last reply
                          0
                          • J JonB
                            5 Mar 2025, 12:10

                            @FleetingMemory
                            Well I don't find anything like you do. Here is a sample I think you should try:

                            #ifndef WIDGET_H
                            #define WIDGET_H
                            
                            #include <QtCharts>
                            #include <QWidget>
                            
                            class Widget : public QWidget
                            {
                                Q_OBJECT
                            
                            public:
                                Widget(QWidget *parent = nullptr);
                                ~Widget();
                            
                            private:
                                QChart *chart;
                                QChartView *chartView;
                            
                            private slots:
                                void deleteChart();
                            };
                            #endif // WIDGET_H
                            
                            #include <QDebug>
                            #include <QElapsedTimer>
                            #include <QTimer>
                            #include <QVBoxLayout>
                            
                            #include "widget.h"
                            
                            // using namespace QtCharts;
                            
                            Widget::Widget(QWidget *parent)
                                : QWidget(parent)
                            {
                                setGeometry(100, 100, 800, 600);
                                setLayout(new QVBoxLayout);
                            
                                this->chart = new QChart();
                                this->chartView = new QChartView(chart, this);
                                layout()->addWidget(chartView);
                                chartView->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
                            
                                for (int i = 0; i < 10; i++)
                                {
                                    QLineSeries* series = new QLineSeries();
                                    for (int x = 0; x < 50000; x++)
                                        series->append(x, x * (i + 1));
                                    chart->addSeries(series);
                                }
                            
                                QTimer::singleShot(2000, this, &Widget::deleteChart);
                            }
                            
                            void Widget::deleteChart()
                            {
                                QElapsedTimer elapsed;
                                qDebug() << "Starting to delete";
                                elapsed.start();
                                layout()->removeWidget(chartView);
                                delete chart;
                                chart = nullptr;
                                delete chartView;
                                chartView = nullptr;
                                qDebug() << "Finished deleting" << elapsed.elapsed();
                            }
                            
                            Widget::~Widget() {}
                            

                            500,000 points, 10 series. For me this takes 6 milliseconds to "delete", where you claim 30 seconds! Ubuntu 24.04, VirtualBox slow machine/not nearly as much memory as you, Qt 6.4.2 supplied with Ubuntu. How long does it take you?

                            Possible it could be slow if compiled for Debug, though that is actually how I ran mine, you might check whether Release makes a huger difference?

                            F Offline
                            F Offline
                            FleetingMemory
                            wrote on 5 Mar 2025, 15:38 last edited by
                            #19

                            @JonB I think its not the number of points in a singular line, but the number of series (lines) in total causing the problem. My times I listed are from running on release.

                            J J 2 Replies Last reply 5 Mar 2025, 15:41
                            0
                            • F FleetingMemory
                              5 Mar 2025, 15:38

                              @JonB I think its not the number of points in a singular line, but the number of series (lines) in total causing the problem. My times I listed are from running on release.

                              J Online
                              J Online
                              JonB
                              wrote on 5 Mar 2025, 15:41 last edited by JonB 3 May 2025, 15:43
                              #20

                              @FleetingMemory
                              I asked you to produce a minimal example such as mine but you have not. I said earlier I was guessing 10 series to make 500,000 points. If you want help I don't see why you can't convey the necessary information, no point leaving me to create 10 series I mentioned and then say it's not the right number..... And you could always alter my code to whatever numbers you desire to test.....

                              1 Reply Last reply
                              0
                              • F FleetingMemory
                                5 Mar 2025, 15:38

                                @JonB I think its not the number of points in a singular line, but the number of series (lines) in total causing the problem. My times I listed are from running on release.

                                J Offline
                                J Offline
                                JoeCFD
                                wrote on 5 Mar 2025, 15:44 last edited by JoeCFD 3 May 2025, 15:46
                                #21

                                @FleetingMemory try to call
                                removeAllSeries() first. It seems this call will not trigger update of qchart.
                                and then update,
                                next delete chart.

                                F 1 Reply Last reply 5 Mar 2025, 15:51
                                1
                                • J JoeCFD
                                  5 Mar 2025, 15:44

                                  @FleetingMemory try to call
                                  removeAllSeries() first. It seems this call will not trigger update of qchart.
                                  and then update,
                                  next delete chart.

                                  F Offline
                                  F Offline
                                  FleetingMemory
                                  wrote on 5 Mar 2025, 15:51 last edited by
                                  #22

                                  @JoeCFD Will give this a try and let you know!

                                  J 1 Reply Last reply 5 Mar 2025, 16:08
                                  0
                                  • F FleetingMemory
                                    5 Mar 2025, 15:51

                                    @JoeCFD Will give this a try and let you know!

                                    J Online
                                    J Online
                                    JonB
                                    wrote on 5 Mar 2025, 16:08 last edited by
                                    #23

                                    @FleetingMemory
                                    In your first post of the steps you have tried you already included

                                    Removing all series prior to deleting

                                    1 Reply Last reply
                                    0
                                    • F Offline
                                      F Offline
                                      FleetingMemory
                                      wrote on 5 Mar 2025, 16:16 last edited by
                                      #24

                                      Yeah, I am going to retry in release with elapsed() to see what is going on and give more info.
                                      Query Size 450,000 points. Spread across 12,000 series.
                                      populating the series after query takes 2,964 milliseconds
                                      Gets stuck on remove all series (freezes main thread), takes 35,774 milliseconds to remove

                                      J 1 Reply Last reply 5 Mar 2025, 17:01
                                      0
                                      • F FleetingMemory
                                        5 Mar 2025, 16:16

                                        Yeah, I am going to retry in release with elapsed() to see what is going on and give more info.
                                        Query Size 450,000 points. Spread across 12,000 series.
                                        populating the series after query takes 2,964 milliseconds
                                        Gets stuck on remove all series (freezes main thread), takes 35,774 milliseconds to remove

                                        J Online
                                        J Online
                                        JonB
                                        wrote on 5 Mar 2025, 17:01 last edited by
                                        #25

                                        @FleetingMemory
                                        Yes please test. OOI how can you expect to display 12,000 series to a user, I just don't get it?

                                        1 Reply Last reply
                                        0
                                        • F Offline
                                          F Offline
                                          FleetingMemory
                                          wrote on 5 Mar 2025, 17:08 last edited by
                                          #26

                                          A little more testing - I used release mode, removed all series from QChart in a QChartView after a new query is run. During this test I re-used the same QChart -- after running removeAllSeries(), I used the points from the query to generate new series and add them to the chart. Points are formatted <millis since epoch, value>. Series have OpenGL turned on in this test.

                                          1: A Query is run, Qlist<Qlist<QPointF>> generated. I return the Query Count
                                          2: If QChart Exists, remove all series (this I timed)
                                          3: for each Qlist<QPointF> generate a new series with replace(), append Axes and insert into chart (this I timed)

                                          Query Size 450,000 points. Spread across 12,000 series.
                                          populating 12,000 series after query takes 2.964 s
                                          Gets stuck on remove all 12,000 series (freezes main thread), takes 35.774 seconds to remove

                                          Query Size: 332,000 points
                                          populating 10,600 series: 3.3s
                                          populating 2nd time diff data: 3.4s
                                          removing all series: 25.35s
                                          removing all (2nd time diff data): 25.6s

                                          Query Size: 247,900 points
                                          populating 9300 series: 2.5s
                                          removing all series: 19s

                                          Query Size 250,000
                                          Populating Series: 1.32 s
                                          removing all 8,050 series: 14.33s
                                          removing all 8,050 series (2nd run diff data): 13.4s

                                          Query Size 223,200
                                          Populating 8600 series: 2.4s
                                          populating 8600 series(2nd run diff data): 2s
                                          removing all series: 15.6s
                                          removing all series (2nd run diff data): 15.6s

                                          Query Size: 195,600
                                          populating series: 1.7s
                                          Removing 7820 series: 12.5s
                                          removing all 7820 series (2nd run diff data): 12.9s

                                          Query Size 158,543
                                          populating the series after query: 0.7s
                                          removing all 4,859 series: 4.9s

                                          Query Size 21700
                                          Removing 1240 series: 0.395s
                                          populating series: 0.1s

                                          Query Size: 9,818
                                          populating series: 0.04s
                                          removing all 735 series: 0.045s
                                          removing all 735 series (2nd run diff data): 0.044s

                                          Performance seems to get worse pretty quickly at a non-linear rate

                                          If it helps, I am compiling this as a plugin loaded in a simple main application (though that shouldn't affect things).
                                          I have tried with useOpenGL both on and off. As far as I can tell, it makes little difference.
                                          The fact the removeAll/delete freezes the main thread, which essentially locks up the entire application it is running in is a huge issue for me...

                                          J J 2 Replies Last reply 5 Mar 2025, 17:13
                                          0

                                          16/51

                                          5 Mar 2025, 13:59

                                          35 unread
                                          • Login

                                          • Login or register to search.
                                          16 out of 51
                                          • First post
                                            16/51
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved