Qt charts integration with c++



  • Hi there
    I'm looking for an explanation, or example, on how to integrate qt Charts QML elements with data from the c++ part.
    For example, how to draw a LineSeries QML Type, with data that are passed from a c++ object.
    All helps pages and examples that come with qt 5.7 have dummy data directly defined in the QML files.
    Thanks for your help.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should start by reading the QML Cpp integration chapter from Qt's documentation. There you have the explanation on how to mix both worlds.



  • Hi
    Thank you for your answer. I'm used to the QML / c++ integration, and I'm already using several of those integration scheme in my projects. However regarding this Qt Charts integration, things seems a little more confused to me. Maybe there is nothing very complicated here, but if you could be a little more specific on the mechanism to use, it would really help me a lot.

    For exmple, I want to display a Line graph on my QML page. I then declare :

    ChartView {
             title: "Line"
             LineSeries {
                 name: "LineSeries"
                 ...
             }
         }
    

    In all examples, the data comes from inside the LineSeries in the QML, by declaring XYPoint in it.

    In my real case, the data has to come from a c++ object. How to make the connection between this object and the LineSeries ?

    Shall I instantiate a QLineSeries derived-object on the c++ side, and make it available in the QML context ? But how to do that in that specific case ? and ho to insert this object into my LineSeries ? I see no "data" property in this QML type, that would allow me to "point" to the proper c++ object's method.

    Thanks again for your help.
    MK


  • Lifetime Qt Champion

    I haven't tested it but one possible way would be to get the LineSeries object generated in your QML code from C++ and then interact with that object directly.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.