Solved 'setAxisY' is deprecated in Qt Charts
-
i want to remove the warnings
mChart->setAxisY (mAxisY, mSeriesList.at(i));
what will be the right way to fix this waring?
i did the fix for other and are those correct?
mChart->axes(Qt::Horizontal).back()->setRange(0,60); // mChart->axisX()->setRange(0, 60); mChart->axes(Qt::Horizontal).back()->setReverse(true); // mChart->axisX()->setReverse(true);
-
@saber What warning exactly do you get? There is no mention of https://doc.qt.io/qt-5/qchart.html#setAxisX being deprecated. In general the correct solution to get rid of deprecated methods is to use the new ones.
-
@jsulm
qt 5.12 is givinf that/home/shaber/Desktop/apps/dashboard/history_chart.cpp:22: warning: ‘void QtCharts::QChart::setAxisY(QtCharts::QAbstractAxis*, QtCharts::QAbstractSeries*)’ is deprecated [-Wdeprecated-declarations] mChart->setAxisY(mAxisY, mSeriesList.at(i)); ^
i found this stack orevflow
-
@saber Interesting. These methods are really set as depreceted (https://code.woboq.org/qt5/qtcharts/src/charts/qchart.h.html).
But in the documentation there is no information about it. I never used Qt Charts, so don't know what is the replacement.
Maybe somebody else knows.
You could alsy file a bug for the documentation to add missing information. -
@jsulm
that will be good idea where i can do that? -
@saber said in 'setAxisY' is deprecated:
that will be good idea where i can do that?
-
bug repoting is too complicated for me. i am not doing it
-
solution
mChart->axes(Qt::Vertical, mSeriesList.at(i)).append(mAxisY);
-
I found the following to be an acceptable replacement:
m_chart->addAxis(m_xAxis, Qt::AlignBottom); m_chart->addAxis(m_yAxis, Qt::AlignLeft);
-
In fact, the resolution is described here:
https://doc-snapshots.qt.io/qt5-5.12/qchart-obsolete.htmlThis function is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
Use addAxis() instead.
-
just an additional comment, addAxis adds the axis to the chart, but then you need to attach the axis to your series using attachAxis. In your case you can substitute this:
mChart->setAxisY (mAxisY, mSeriesList.at(i));
with:
mChart->addAxis(mAxisY, Qt::AlignLeft); mSeriesList.at(i)->attachAxis(mAxisY); --> you can also put this in a loop