title: Why Qt chart example does not delete dynamically allocated variables
body: <p>I have been checking the Qt BarChart example, I noticed that the dynamically allocated variables were not deleted at all, why? I try to copy the idea of this example, then use in a layout, and display the chart in a plainTextEditor. However, I want to delete these dynamically allocated variables once I display the chart, but I don't know when and where to delete them. I tried to delete them at the end of the function, but it won't show anything on the plainTextEditor. I don't want to define these dynamically allocated variables as a member variables and delete them in the Destructor.</p>
  
  <p>Here are the example I get from the Qt Documentation </p>
  
  <pre><code>&gt; #include &lt;QtWidgets/QApplication&gt;
  &gt; #include &lt;QtWidgets/QMainWindow&gt;
  &gt; #include &lt;QtCharts/QChartView&gt;
  &gt; #include &lt;QtCharts/QBarSeries&gt;
  &gt; #include &lt;QtCharts/QBarSet&gt;
  &gt; #include &lt;QtCharts/QLegend&gt;
  &gt; #include &lt;QtCharts/QBarCategoryAxis&gt;
  &gt; 
  &gt; QT_CHARTS_USE_NAMESPACE
  &gt; 
  &gt; int main(int argc, char *argv[]) {
  &gt;     QApplication a(argc, argv);
  &gt; 
  &gt;     QBarSet *set0 = new QBarSet("Jane");
  &gt;     QBarSet *set1 = new QBarSet("John");
  &gt;     QBarSet *set2 = new QBarSet("Axel");
  &gt;     QBarSet *set3 = new QBarSet("Mary");
  &gt;     QBarSet *set4 = new QBarSet("Samantha");
  &gt; 
  &gt;     *set0 &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; 3 &lt;&lt; 4 &lt;&lt; 5 &lt;&lt; 6;
  &gt;     *set1 &lt;&lt; 5 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 4 &lt;&lt; 0 &lt;&lt; 7;
  &gt;     *set2 &lt;&lt; 3 &lt;&lt; 5 &lt;&lt; 8 &lt;&lt; 13 &lt;&lt; 8 &lt;&lt; 5;
  &gt;     *set3 &lt;&lt; 5 &lt;&lt; 6 &lt;&lt; 7 &lt;&lt; 3 &lt;&lt; 4 &lt;&lt; 5;
  &gt;     *set4 &lt;&lt; 9 &lt;&lt; 7 &lt;&lt; 5 &lt;&lt; 3 &lt;&lt; 1 &lt;&lt; 2;
  &gt; 
  &gt;     QBarSeries *series = new QBarSeries();
  &gt;     series-&gt;append(set0);
  &gt;     series-&gt;append(set1);
  &gt;     series-&gt;append(set2);
  &gt;     series-&gt;append(set3);
  &gt;     series-&gt;append(set4);
  &gt; 
  &gt; 
  &gt;     QChart *chart = new QChart();
  &gt;     chart-&gt;addSeries(series);
  &gt;     chart-&gt;setTitle("Simple barchart example");
  &gt;     chart-&gt;setAnimationOptions(QChart::SeriesAnimations);
  &gt; 
  &gt;     QStringList categories;
  &gt;     categories &lt;&lt; "Jan" &lt;&lt; "Feb" &lt;&lt; "Mar" &lt;&lt; "Apr" &lt;&lt; "May" &lt;&lt; "Jun";
  &gt;     QBarCategoryAxis *axis = new QBarCategoryAxis();
  &gt;     axis-&gt;append(categories);
  &gt;     chart-&gt;createDefaultAxes();
  &gt;     chart-&gt;setAxisX(axis, series);
  &gt; 
  &gt;     chart-&gt;legend()-&gt;setVisible(true);
  &gt;     chart-&gt;legend()-&gt;setAlignment(Qt::AlignBottom);
  &gt; 
  &gt;     QChartView *chartView = new QChartView(chart);
  &gt;     chartView-&gt;setRenderHint(QPainter::Antialiasing);
  &gt; 
  &gt;     QMainWindow window;
  &gt;     window.setCentralWidget(chartView);
  &gt;     window.resize(420, 300);
  &gt;     window.show();
  &gt; 
  &gt;     return a.exec(); }
  </code></pre>