Need Help to Improve QML QChartView and CPP Interaction
-
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. -
Take a look at
VXYModelMapper
. It lets you create series from a QAbstractTableModel with not all the glue code you did here.