Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved How to acess PieSlice in Backend?

    General and Desktop
    2
    2
    181
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zrrr1 last edited by zrrr1

      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? 0_1528555123803_Capturar.PNG

      1 Reply Last reply Reply Quote 0
      • KillerSmath
        KillerSmath last edited by KillerSmath

        @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/6

        You 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();
            }
        ...
        

        @Computer Science Student - Brazil
        Web Developer and Researcher
        “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

        1 Reply Last reply Reply Quote 2
        • First post
          Last post