QCustomPlot Discussion and Comments

Passing std::vector to QCustomPlot without duplicating data?Return to overview


I'm working with a C++ library that takes a pointer to std::vector<double> and iterates over it, potentially reading millions of values. However, I also plot that data using QCustomPlot, which handles huge data sets quite nicely I'm relieved to find.

The lib wants a std::vector<double>, QCustomPlot wants a QVector<double>. Is there a way to keep them both happy without duplicating the data into two vectors? The copy is fast enough, it just feels like a waste of memory.


In the background, QCustomPlot graphs actually use their own storage unit. Even if you used a QVector, it would still copy the data. You could however get rid of at least one of those copies by setting the QVector data pointer to the same pointer as the std vector pointer.

Got it, thanks for the info!

It looks like that might be the best way, someone on the Qt forums also suggested I look into that. Another possibility that was mentioned was modifying QCustomPlot to work with std::vector, since we have access to the source.

It would be quite simple to modify the setData function so that it takes in an std::vector, but you would still be copying data to the internal structures.

BUT, You would have a really hard time modifying QCustomPlot to work with std::vector the way you want it to work with it. Modifying QCustomPlot to use std::vector in the internal structures would take you months.