I had the same problem. I have four plots in one window what needs update every 500ms and each call to replot takes about 600ms on my xeon server at 3 ghz (!!!).
but i found a solution. it requires modifying the source code, and is not truely running from a secondary thread. The thing is, only calls made to QWidget to paint the plot requires to me made from the Gui thread. other processing can be made in different thread. So here is the mod based on the beta release of v2.0:
qcustomplot.h: create a overload of the replot() function in line 3698. this new overload has a bool variable which when false, will draw the plot in the buffer, and when true will draw the already buffered plot onto the window by calling repaint() function in QWidget.
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpRefreshHint); //orginal code
Q_SLOT void replot(bool step, QCustomPlot::RefreshPriority refreshPriority = QCustomPlot::rpRefreshHint); //added code
qcustomplot.cpp: define the new overload
void QCustomPlot::replot(bool step, QCustomPlot::RefreshPriority refreshPriority)
if (mReplotting) // incase signals loop back to replot slot
mReplotting = true;
// draw all layered objects (grid, axes, plottables, items, legend,...) into their buffers:
foreach(QCPLayer *layer, mLayers)
for (int i = 0; i < mPaintBuffers.size(); ++i)
if ((refreshPriority == rpRefreshHint && mPlottingHints.testFlag(QCP::phImmediateRefresh)) || refreshPriority == rpImmediateRefresh)
mReplotting = false;
call from GUI thread will look like this:
void Class::CUpdatePlots(mca_plots plot_data, Class *pt)
for (int ch = 0; ch < 4; ch++)
future[ch] = QtConcurrent::run(Class::CPlots, ch,
QVector<double>::fromStdVector(v1), QVector<double>::fromStdVector(v2), pt);
void Class::CPlots(int ch, QVector<double> va1, QVector<double> va2, Class *pt)
/*if (ch == 3)
at this point all the layers of the plot have been made in the buffer. all you have to do is call onto the
; from your GUI thread to make the plot reapear magically. takes about 50ms to put out the image. no more stuck GUI!