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. Need Help to Improve QML QChartView and CPP Interaction
Forum Updated to NodeBB v4.3 + New Features

Need Help to Improve QML QChartView and CPP Interaction

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtchartsqmlqchartviewcpp
2 Posts 2 Posters 545 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
    Sandip Rakhasiya
    wrote on last edited by Sandip Rakhasiya
    #1

    Hello,

    I am developing a Qt QML application for Embedded devices. And wants some guide to smooth Qt Charts interaction.

    Below is my code description.
    I have created ChartView in plotPage.ui.qml and also added Axis in ChartView as follows.

        ChartView {
            id: chartView
            visible: true
            anchors.left: parent.left
            anchors.right: parent.right
            anchors.top: dividerBar.bottom
            anchors.bottom: imageShiftRight.top
            anchors.rightMargin: -20
            anchors.leftMargin: -20
            anchors.bottomMargin: -20
            anchors.topMargin: -20
            backgroundColor: "transparent"
            plotAreaColor: whiteColor
            antialiasing: true
            legend.visible: false
    
            ValueAxis {
                id: xAxis
                labelsFont.pointSize: fontSizeSmall
                titleText: "Freq"
                labelsColor: "white"
                min: 0
                max: 500
                tickCount: 8
            }
    
            ValueAxis {
                id: yAxis
                labelsFont.pointSize: fontSizeSmall
                titleText: "Magnitudes"
                labelsColor: "white"
                min: 0
                max: 50
                tickCount: 8
            }
        }
    
    

    I have created spline series for ChartView dynamically with the below code.

    onCurve: {
                var series = chartView.createSeries(ChartView.SeriesTypeSpline, title, xAxis, yAxis)
                interface.plotUpdate(series) //interface is CPP file instance and plotUpdate is CPP function.
    }
    

    I have collecting data in CPP and creating points with QPointF.
    Note: In one chart there are 1000+ points and I will need to update 8 or 24 charts in one instance.
    So, I am updating with the below function.

    void Interface::plotUpdate(QAbstractSeries *series)
    {
        if (series) {
            QSplineSeries *splineseries = static_cast<QSplineSeries *>(series);
            QVector<QPointF> points = m_data;
            splineseries->replace(points);
        }
    }
    
    void Interface::createPlotData(int converted[], float data[], int start_idx, int totalPoints, bool inverted)
    {
        m_data.clear();
        int counter = 0;
    
        for(counter = 0; counter < totalPoints; counter++) {
            m_data.append(QPointF(((double)converted[counter] * 0.001), (inverted ? (double)data[counter + start_idx] * -1.0 : (double)data[counter + start_idx])));
        }
    }
    
    Calling in other functions.
    
            createPlotData(Freq, data[0], 0, points);
            emit curve(tr("Main"), true);
    
    

    emit curve goes to QML and In QML -> onCurve {} updating data from CPP.

    All things are working fine but For one graph, it is taking too much time.
    I need to reduce time to update the plot each time. I have use linuxfb as a QT Platform to render UI.

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      Take a look at VXYModelMapper . It lets you create series from a QAbstractTableModel with not all the glue code you did here.

      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