Hello CP members,
Yes, I know that one cannot use GUI things from non-GUI threads. thats why i am trying to "do process" in worker thread(Non-GUI) than coming back to GUI thread(main thread) to display Graph. but getting following error.
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QCustomPlot(0x15b9a988), parent's thread is QThread(0x14547f90), current thread is QThread(0x15ba56c8)
whar i am doing in my code is as following..
from Main thread going to worker thread(NON-GUI). Worked thread is processing data and writing it into a txt FILE. after finishing the processing I am trying to kill the worker thread.
in AnalysisworkerThread.cpp
AnalysisWorkerThread::BusLoadAvg();
GenSetPayloadAna gSetPayloadAnalysis;
gSetPayloadAnalysis.PayloadAnalysisDisplay();
emit OnFinishAnalysis();
SIGNAL OnFinishAnalysis() is connected to SLOT AfterFinishAnalysis()
connect(this, SIGNAL(OnFinishAnalysis()),this,SLOT(AfterFinishAnalysis()));
void AnalysisWorkerThread::AfterFinishAnalysis()
{
mwobj.DisplayGraph();
}
in mainWindow.cpp DisplayGraph() simply trying to upload a Sample graph
void MainWindow::DisplayGraph()
{
qDebug()<<"Back to Main Thread";
QVector<double> x(101), y(101);
for (int i=0; i<101; ++i)
{
x[i] = i/50.0 - 1;
y[i] = x[i]*x[i];
}
ui->customPlot->addGraph();
ui->customPlot->graph(0)->setData(x, y);
ui->customPlot->xAxis->setLabel("x");
ui->customPlot->yAxis->setLabel("y");
ui->customPlot->xAxis->setRange(-1, 1);
ui->customPlot->yAxis->setRange(0, 1);
ui->customPlot->replot();
}
WOULD BE NICE IF SOMEONE CAN help me where i am doing wrong .....
Thanks
What I have tried:
I am trying as i added above when i try to Kill the thread as it finished than it is going to crash the Application
in Anlysisworkerthread.cpp
connect(this, SIGNAL(finished()), this, SLOT(deleteLater()));