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