Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Pass data from C++ to qml using signals to update charts at runtime
Forum Update on Monday, May 27th 2025

Pass data from C++ to qml using signals to update charts at runtime

Scheduled Pinned Locked Moved QML and Qt Quick
chartsc++signal
1 Posts 1 Posters 1.7k Views
  • 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.
  • S Offline
    S Offline
    SaranshVora
    wrote on last edited by
    #1

    Hello,
    I want to pass data from C++ file to qml file for line series at runtime without using timer. ```
    //CPP (I am calling the function qmlregistertype for this class in another .cpp file)
    ``
    class GraphicalDisplayItem : public QObject
    {
    Q_OBJECT
    Q_PROPERTY(double dataReadX READ dataReadX NOTIFY dataChanged)
    Q_PROPERTY(double dataReadY READ dataReadY NOTIFY dataChanged)

    public:
    	explicit GraphicalDisplayItem(QObject *parent = 0);
    	~GraphicalDisplayItem();
    
    	double dataReadX();
    	double dataReadY();
    	void updateData(double value);
    	
    
    Q_SIGNALS:
        void dataChanged();
    

    // definitions of dataReadX and update data
    double GraphicalDisplayItem::dataReadX()
    {
    static int i = 0;
    return x.at(++i);
    }

    void GraphicalDisplayItem::updateData(double value)
    {
    x.push_back(x_limit++);
    y.push_back(value);
    start = true;
    dataChanged();// based on this signal call I want to update the data in the charts how can I do that ?
    }

    //QML :
    ```Item {
        id: valueDisp
    
        implicitWidth: 640
        implicitHeight: 640
        property int currentIndex: 0
        property int j: 0;
        property int position:0;
        property double datax:0;
        property double datay:0;
    
        ChartView {
               id:chartView
                title: "Data Output"
                anchors.fill: parent
                legend.visible: false
                antialiasing: true
    
                MouseArea {
                           anchors.fill: parent
                          // onClicked: {
    
                                          }
    
                ValueAxis {
                    id: axisX
                   // title:"iterations"
                    min:0
                    max:100
                    tickCount: 9
    
                }
    
                ValueAxis {
                    id: axisY
                   // title:"Value"
                    min: 0
                    max: 100
                    tickCount: 1
    
                    }
    
                LineSeries {
    
                            id:lineSeries
                            name:"Data Output"
                            axisX:axisX
                            axisY:axisY
                            useOpenGL: true
                              }
    
     }
        GraphicalDisplayItem{
           onDataChanged:
       {
    
                                 lineSeries.append(componentData.dataReadX , componentData.dataReadY)
        }
         }
    }
    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved