Kyle Strand Kyle Strand - 1 year ago 152
C++ Question

Iterate over points in QML XYSeries

I'm trying to iterate over the points in the Qt 5.5 QtCharts

type, which inherits from

I tried a simple
-loop, but I can't figure out a way to determine the number of points in the series:

for (var i=0; i < my_line_series.contentItem.children.length; ++i) {
// do something with the index

Unfortunately, it seems that none of the following are members of

  • contentItem

  • children

  • length

  • count

  • size

Alternatively, I could try iterating over the series until there's no point to access at the given index--but the method used to access a point at a given index,
, returns
if the index is invalid, and it's entirely possible that there are real
points in my

....So is it possible to do this iteration in pure QML (see edit)?

EDIT: The underlying C++ type
provides the
method, so it's possible to pass the
QML type to a
method taking a
and get the size that way. This seems like an absurd workaround for a simple problem, though.

Answer Source

The QML LineSeries type simply does not provide access to the methods that are required for any non-trivial tasks involving the series.

The solution is to implement these tasks in C++ by passing the LineSeries QML type to a Q_INVOKABLE method taking a QAbstractSeries*.