QT QCustomPlot in a new thread

2019-08-31 06:12发布

问题:

In my UI, I have a QCustomPlot and I have generatePlot function which uses from this QCustomPlot and runs in a new thread as follows:

future = QtConcurrent::run(this, &MainWindow::generatePlot);

In generatePlot function, I create QCPbars like this:

QCPBars *bar = new QCPBars(customPlot->xAxis, customPlot->yAxis);

But, I get this error:

QObject: Cannot create children for a parent that is in a different thread.

I think that's because the thread of customPlot is diffrenet from bar. How can I solve it?