I'm trying to make an Oscilloscope like Qt Quick application, based on the qtcharts-qmloscilloscope-example here
In this example the traces (a QTQuick ChartView) are pre-allocated in the QML and updated via a timer.
I would like to be able to add and remove traces at runtime.
The existing application passes a reference to the underlying data array as QAbstractSeries of QPointF objects. This action is triggered on a Timer, thus:
Timer {
id: refreshTimer
interval: 1 / 1 * 1000 // 1 Hz
running: dataSource.isRunning
repeat: true
onTriggered: {
dataSource.updateTime();
//dataSource.update(chartView.series(0));
//dataSource.update(chartView.series(1));
//dataSource.update(chartView.series(2));
dataSource.update(chartView);
}
}
And the existing update method looks like this:
void DataSource::update(QAbstractSeries * series)
{
...
}
This is OK if you only want a fixed number of traces and they are all updated individually. But I would like to be able to add traces as they are turned on and off.
I've tried to pass the chartView ID to an update(QChartView *) function but this always breaks with a null pointer.
Q_INVOKABLE void DataSource::update(QChartView * view)
{
...
}
I've also tried using window->findChildren at the top level and passing that to the instance of DataSource. That gets a valid pointer but of type QQuickItem. If I cast that to a QChartView I also get a null pointer.
How to I correctly pass a pointer to a QChartView object to C++?