QT QCharts add and remove series
<p>How i should add and remove series from qchart?</p>

<p>The main mess is that QChart some how store QAxis and QSeries, QSeries themselves refer to QAxis.Above that all that objects are heavy connected. </p>

<p>So instead of pseudo code like this:</p>

<pre><code> void someclass::set_series(QLineSeries*someQLineSeries){
 somechart-&gt;removeAllSeries();
 somechart-&gt;removeAllAxis();
 somechart-&gt;addSeries(someQLineSeries);
 }
</code></pre>

<p>I should use that:
(zlineseries additionaly store 2 pointers to its axis)</p>

<pre><code>void zhplotview::attach_dt_series(ZLineSeries *series)
if(chart)
{

    qDebug()&lt;&lt;"NOT DELETED CHART";
    if(viewer)
    {
        qDebug()&lt;&lt;"NOT DELETED VIEWER";
        qDebug()&lt;&lt;"Okay. Try to clear old links and create chart again";

        //let chart have 1 series
        auto slist=chart-&gt;series();
        ZLineSeries *old_series=dynamic_cast&lt;ZLineSeries*&gt;(slist.at(0));

        old_series-&gt;detachAxis(old_series-&gt;axis_x);
        old_series-&gt;detachAxis(old_series-&gt;axis_y);

        chart-&gt;removeAxis(old_series-&gt;axis_x);
        chart-&gt;removeAxis(old_series-&gt;axis_y);
        vbl-&gt;removeWidget(viewer);

        chart-&gt;removeSeries(old_series);

        disconnect(viewer);
        disconnect(chart);

        delete chart;
        delete viewer;

    }
    else
    {
        qDebug()&lt;&lt;"chart is 0, but viewer not";
        return;
    }
}

chart=new QChart();
chart-&gt;addSeries(series);
chart-&gt;addAxis(series-&gt;axis_x,Qt::AlignBottom);
chart-&gt;addAxis(series-&gt;axis_y,Qt::AlignLeft);
series-&gt;attachAxis(series-&gt;axis_x);
series-&gt;attachAxis(series-&gt;axis_y);

viewer=new QZChartView(chart,this);
vbl-&gt;addWidget(viewer);
</code></pre>