QOpenGLContext used in multithread
-
Hi,guys.I met a problem. I used QGraphicsView to display 3D animation by integration with OpenSceneGraph.Meanwhile i capture QGraphicsView's image to generate a video file.
In main thread i use (dynamic_cast<QOpenGLWidget *>(m_pGraphicsView->viewport()))->context()->functions()->glReadPixels() ,it can work,but the animation will be nonfluency.
So I create another thread to capture QGraphicsView's image to generate a video file.So i pass m_pGraphicsView to thread,and use same code.But in this thread i can't capture image, :(.
I find somebody says the problem is QOpenGLContext can't be used in another thread,they use QOpenGLContext->moveToThread,etc. I don't understand well.
Can any one help me? I list my code snippet:
void CMainWindow::recordView()
{m_pAVIGenerator = new FFMPEG(m_pGraphicsView); m_pAVIGenerator->SetupVideo(filePath, 1480, 920, 25, 10, 40000000); m_pAVIGenerator->start(); //m_pAVIGenerator is my another thread
}
void FFMPEG::run()
{while (!mNeedStop) { QImage image(1480, 920, QImage::Format_RGB888); (dynamic_cast<QOpenGLWidget *>(m_pView->viewport()))->context()->functions()->glReadPixels(192, 0, 1480, 920, GL_RGB, GL_UNSIGNED_BYTE, image.bits()); .......... WriteFrame((char *)image.bits()); }
}
How can i change these code?Thanks for your patient read my problem!