<?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[QOpenGLWidget update and grab in thread]]></title><description><![CDATA[<p dir="auto">How to do it correctly?</p>
<ol>
<li>Create Thread</li>
<li>Create in thread object based on QOpenGLWidget</li>
<li>in Thread call grab() and take correct picture</li>
</ol>
<p dir="auto">I open example hellogl2 and add this sample code in main.cpp before <code>return app.exec();</code></p>
<pre><code>    QShortcut *shortcutF4 = new QShortcut(QKeySequence(Qt::Key_F4), &amp;mainWindow, nullptr, nullptr, Qt::ApplicationShortcut);
    QObject::connect(shortcutF4, &amp;QShortcut::activated, &amp;mainWindow, [&amp;]()
    {
        qDebug() &lt;&lt; "F4";
        auto *t = new std::thread([]()
        {
             GLWidget glWidget;
             glWidget.resize(400,400);
             glWidget.grab().save("grab_hellogl2_in_thread_01.png");
             // change something
             glWidget.setXRotation(60*3);
             glWidget.grab().save("grab_hellogl2_in_thread_02.png");
             // change something
             glWidget.setYRotation(75*4);
             glWidget.grab().save("grab_hellogl2_in_thread_03.png");

        });
        t-&gt;join();
    });

    return app.exec();
</code></pre>
<p dir="auto">But I see warning "Attempting to create QWindow-based QOffscreenSurface outside the gui thread. Expect failures."</p>
<p dir="auto">How to do it correctly?</p>
]]></description><link>https://forum.qt.io/topic/146111/qopenglwidget-update-and-grab-in-thread</link><generator>RSS for Node</generator><lastBuildDate>Sun, 25 Oct 2026 12:58:24 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/146111.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 30 Jun 2023 11:46:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QOpenGLWidget update and grab in thread on Fri, 30 Jun 2023 19:56:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfromolsztyn">@<bdi>MfromOlsztyn</bdi></a> As others said you can't render to a widget in any thread but main. For rendering in another thread use <a href="https://doc.qt.io/qt-6/qoffscreensurface.html" target="_blank" rel="noopener noreferrer nofollow ugc">QOffscreenSurface</a> instead of QOpenGLWidget, which creates a windowless surface and is specifically designed for this purpose.</p>
]]></description><link>https://forum.qt.io/post/763227</link><guid isPermaLink="true">https://forum.qt.io/post/763227</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Fri, 30 Jun 2023 19:56:25 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget update and grab in thread on Fri, 30 Jun 2023 18:57:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/wrosecrans">@<bdi>wrosecrans</bdi></a> I look at <a href="https://doc.qt.io/qt-6/qopenglwidget.html#threading" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qopenglwidget.html#threading</a></p>
<pre><code>*Performing offscreen rendering on worker threads, 
for example to generate textures that are then used 
in the GUI/main thread in paintGL(), are supported by exposing 
the widget's QOpenGLContext so that additional contexts 
sharing with it can be created on each thread.*
</code></pre>
<p dir="auto">I don't want to touch main from background thread  ,<br />
and I don't want to touch background thread from main.<br />
Two independent threads, no interaction</p>
<p dir="auto">Another way: create second process without GUI and use QOpenGLWidget in invisible APP,  is it possible ?</p>
<p dir="auto">I'm looking for a starting example<br />
A lot of people ask, but I don't see a solution</p>
]]></description><link>https://forum.qt.io/post/763224</link><guid isPermaLink="true">https://forum.qt.io/post/763224</guid><dc:creator><![CDATA[MfromOlsztyn]]></dc:creator><pubDate>Fri, 30 Jun 2023 18:57:27 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget update and grab in thread on Fri, 30 Jun 2023 17:56:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfromolsztyn">@<bdi>MfromOlsztyn</bdi></a> You can't touch a widget from a secondary thread.  The goal just isn't correct.  There is no way to do that correctly.  Widgets are always "GUI" even if it isn't shown.</p>
<p dir="auto">Threaded OpenGL is potentially a complex topic, but you'll need an offscreen surface that isn't a widget.</p>
]]></description><link>https://forum.qt.io/post/763221</link><guid isPermaLink="true">https://forum.qt.io/post/763221</guid><dc:creator><![CDATA[wrosecrans]]></dc:creator><pubDate>Fri, 30 Jun 2023 17:56:03 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget update and grab in thread on Fri, 30 Jun 2023 13:28:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfromolsztyn">@<bdi>MfromOlsztyn</bdi></a> said in <a href="/post/763187">QOpenGLWidget update and grab in thread</a>:</p>
<blockquote>
<p dir="auto">I don't want to show anything in the GUI</p>
</blockquote>
<p dir="auto">But GLWidget is a widget and therefore needs to be created and access in the main thread as corectly told you already by <a class="plugin-mentions-user plugin-mentions-a" href="/user/ollarch">@<bdi>ollarch</bdi></a> .</p>
]]></description><link>https://forum.qt.io/post/763188</link><guid isPermaLink="true">https://forum.qt.io/post/763188</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 30 Jun 2023 13:28:19 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget update and grab in thread on Fri, 30 Jun 2023 13:29:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ollarch">@<bdi>ollarch</bdi></a><br />
I don't want to show anything in the GUI</p>
<p dir="auto">I want render off-screen,  it is possible in  openGL.</p>
]]></description><link>https://forum.qt.io/post/763187</link><guid isPermaLink="true">https://forum.qt.io/post/763187</guid><dc:creator><![CDATA[MfromOlsztyn]]></dc:creator><pubDate>Fri, 30 Jun 2023 13:29:04 GMT</pubDate></item><item><title><![CDATA[Reply to QOpenGLWidget update and grab in thread on Fri, 30 Jun 2023 11:56:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfromolsztyn">@<bdi>MfromOlsztyn</bdi></a> All the GUI stuff must be done into main thread.</p>
]]></description><link>https://forum.qt.io/post/763178</link><guid isPermaLink="true">https://forum.qt.io/post/763178</guid><dc:creator><![CDATA[ollarch]]></dc:creator><pubDate>Fri, 30 Jun 2023 11:56:15 GMT</pubDate></item></channel></rss>