<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QOpenGLContext used in multithread]]></title><description><![CDATA[<p dir="auto">Hi,guys.I met a problem. I used QGraphicsView to display 3D animation by integration with OpenSceneGraph.<strong>Meanwhile i capture QGraphicsView's image to generate a video file.</strong></p>
<p dir="auto">In main thread i  use  (dynamic_cast&lt;QOpenGLWidget *&gt;(m_pGraphicsView-&gt;viewport()))-&gt;context()-&gt;functions()-&gt;glReadPixels() ,it can work,but the animation will be nonfluency.</p>
<p dir="auto">So I create another thread to capture QGraphicsView's image to generate a video file.<strong>So i pass m_pGraphicsView to thread,and use same code.But in this thread i can't capture image, :(.</strong></p>
<p dir="auto">I find somebody says the problem is QOpenGLContext can't be used in another thread,they use QOpenGLContext-&gt;moveToThread,etc.  I don't understand well.</p>
<p dir="auto">Can any one help me? I list my code snippet:</p>
<p dir="auto">void CMainWindow::recordView()<br />
{</p>
<pre><code>   m_pAVIGenerator = new FFMPEG(m_pGraphicsView);
   m_pAVIGenerator-&gt;SetupVideo(filePath, 1480, 920, 25, 10, 40000000);
   m_pAVIGenerator-&gt;start();
    //m_pAVIGenerator is my another thread
</code></pre>
<p dir="auto">}</p>
<p dir="auto">void FFMPEG::run()<br />
{</p>
<pre><code>while (!mNeedStop)
{
	QImage image(1480, 920, QImage::Format_RGB888);
	(dynamic_cast&lt;QOpenGLWidget *&gt;(m_pView-&gt;viewport()))-&gt;context()-&gt;functions()-&gt;glReadPixels(192, 0, 1480, 920, GL_RGB, GL_UNSIGNED_BYTE, image.bits());
            ..........
	WriteFrame((char *)image.bits());
}
</code></pre>
<p dir="auto">}</p>
<p dir="auto">How can i change these code?Thanks for your patient read my problem!</p>
]]></description><link>https://forum.qt.io/topic/67514/qopenglcontext-used-in-multithread</link><generator>RSS for Node</generator><lastBuildDate>Sun, 15 Nov 2026 11:52:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/67514.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 May 2016 03:09:26 GMT</pubDate><ttl>60</ttl></channel></rss>