##// END OF EJS Templates
Fix memory leak in presenter example
Michal Klocek -
r257:0ac69f2530b6
parent child
Show More
@@ -1,57 +1,59
1 1 #include "chartview.h"
2 2 #include <qlinechartseries.h>
3 3 #include <QTime>
4 4
5 5 ChartView::ChartView(QWidget* parent):QChartView(parent),
6 6 m_index(0)
7 7 {
8 8 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
9 9 m_timer.setInterval(3000);
10 10
11 11 QTime now = QTime::currentTime();
12 12 qsrand((uint)now.msec());
13 13
14 14 QLineChartSeries* series0 = new QLineChartSeries();
15 15 QPen blue(Qt::blue);
16 16 blue.setWidth(3);
17 17 series0->setPen(blue);
18 18 QLineChartSeries* series1 = new QLineChartSeries();
19 19 QPen red(Qt::red);
20 20 red.setWidth(3);
21 21 series1->setPen(red);
22 22 QLineChartSeries* series2 = new QLineChartSeries();
23 23 QPen green(Qt::green);
24 24 green.setWidth(3);
25 25 series2->setPen(green);
26 26
27 27 int numPoints = 10;
28 28
29 29 for (int x = 0; x <= numPoints; ++x) {
30 30 series0->add(x, qrand() % 100);
31 31 series1->add(x, qrand() % 100);
32 32 series2->add(x, qrand() % 100);
33 33 }
34 34
35 35 addSeries(series0);
36 36
37 37 m_series<<series0;
38 38 m_series<<series1;
39 39 m_series<<series2;
40 40
41 41 m_timer.start();
42 42 }
43 43
44 44 ChartView::~ChartView()
45 45 {
46
46 if(m_series.size()==0) return;
47 removeSeries(m_series.at(m_index));
48 qDeleteAll(m_series);
47 49 }
48 50
49 51 void ChartView::handleTimeout()
50 52 {
51 53 if(m_series.size()==0) return;
52 54
53 55 removeSeries(m_series.at(m_index));
54 56 m_index++;
55 57 m_index=m_index%m_series.size();
56 58 addSeries(m_series.at(m_index));
57 59 }
General Comments 0
You need to be logged in to leave comments. Login now