In case your points are sorted in x or y direction you can find much more efficient implementations - like in CurveTracker::curveLineAt in the curvetracker example.
Implementations like QwtPlotCurve::closestPoint - or your adaption - are slow as they are iterating over all points and you often find better solutions using the characteristics of the data or by introducing extra data structures like an R-Tree ( https://www.boost.org/doc/libs/1_63_...roduction.html ).
Not sure, why you are using floats ( QVector2D instead of QLineF ) - but finding the distance between a point and a line is basic school maths and absolutely no reason to violate the GPL by copying trivialities into the source code of your commercial project !
Uwe
Bookmarks