Unsolved How to acess PieSlice in Backend?
-
I have to acess a PieSlice that is in a PieSeries in a ChartView.
The pieSlcie has objectName and i use this code to trie to acess this->slice = engine->rootObjects().at(0)->findChild<QObject*>("graf"); but i can't. Can someone help me? -
@zrrr1
Hi there.I googled about this problem and found an old topic about ChartView Binding to C++ Data
https://forum.qt.io/topic/74675/qml-chartview-binding-to-c-data/6You can get the ChartView object and call the series function and return an object of type AbstractSeries. Then, convert him to QpieSeries type and finally you have all acess of pieS object.
Below is a code demonstrating it:
#include <QAbstractSeries> #include <QPieSerieS> #include <qDebug> ... QObject *chartView = engine.rootObjects().at(0)->findChild<QObject *>("graf"); QtCharts::QAbstractSeries* absSeries; QMetaObject::invokeMethod(chartView, "series", Qt::AutoConnection, Q_RETURN_ARG(QtCharts::QAbstractSeries*, absSeries), Q_ARG(int, 0)); // get the first serie of chart (QML) QtCharts::QPieSeries *pieSeries = qobject_cast<QtCharts::QPieSeries *>(absSeries); // convert to QPieSeries foreach(QtCharts::QPieSlice* slice, pieSeries->slices()){ qDebug() << "Label Name -> " + slice->label(); } ...