<?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[[SOLVED] Cannot set QQuickItem&#x27;s OpenGL version]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I have a QML application and I need to integrate an OpenGL window. So I did:</p>
<p dir="auto"><em>GLViewport.h</em><br />
@    class GLViewport : public QQuickItem{...}<br />
@</p>
<p dir="auto"><em>GLViewport.cpp</em><br />
@    GLViewport::GLViewport()<br />
{<br />
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(HandleWindowChanged(QQuickWindow*)), Qt::DirectConnection);<br />
setFlags(QQuickItem::ItemHasContents);<br />
}</p>
<pre><code>void GLViewport::HandleWindowChanged(QQuickWindow *win)
{
  if (win)
  {
    win-&gt;setSurfaceType(QSurface::OpenGLSurface);

    QSurfaceFormat format;
    format.setRenderableType(QSurfaceFormat::OpenGL);
    format.setSamples(4);
    format.setVersion(3, 2); // &lt;&lt;== this puts a mess!
    format.setProfile&amp;#40;QSurfaceFormat::CoreProfile&amp;#41;;
    win-&gt;setFormat(format&amp;#41;;
    win-&gt;create(&amp;#41;;

    QOpenGLContext *context = new QOpenGLContext;
    context-&gt;setFormat(format&amp;#41;;
    context-&gt;create(&amp;#41;;
    if (!context-&gt;isValid(&amp;#41;)
    {
      std::cout &lt;&lt; "ERROR: cannot set OpenGL context" &lt;&lt; std::endl;
    }
    context-&gt;makeCurrent(win);
</code></pre>
<p dir="auto">[...]</p>
<pre><code>  }
}
</code></pre>
<p dir="auto">@</p>
<p dir="auto">However, the line setFormat(3,2) puts a real mess. Basically, if I comment it, everything works. I have a window with a OpenGL 2.0 and a "internal context" with OpenGL 4.4. Problem is, my viewport needs an OpenGL 3.2 context for drawing our things. How can I achieve that then?</p>
<p dir="auto">Thanks for any help!</p>
<p dir="auto"><em>UPDATE</em><br />
If fact, it does NOT work with "OpenGL under QML example":<a href="http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5/qtquick-scenegraph-openglunderqml-example.html</a> either. If I try to change OpenGL version, I get a black background when doing setVersion(3,2).</p>
]]></description><link>https://forum.qt.io/topic/42236/solved-cannot-set-qquickitem-s-opengl-version</link><generator>RSS for Node</generator><lastBuildDate>Sun, 03 May 2026 21:59:44 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/42236.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 05 Jun 2014 10:00:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Cannot set QQuickItem&#x27;s OpenGL version on Sat, 11 Oct 2014 08:34:29 GMT]]></title><description><![CDATA[<p dir="auto">Forget about asking Qt to use a specific opengl version. It simply does not work on Mac OSX for the moment...</p>
]]></description><link>https://forum.qt.io/post/247028</link><guid isPermaLink="true">https://forum.qt.io/post/247028</guid><dc:creator><![CDATA[Korchkidu]]></dc:creator><pubDate>Sat, 11 Oct 2014 08:34:29 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Cannot set QQuickItem&#x27;s OpenGL version on Fri, 03 Oct 2014 14:15:35 GMT]]></title><description><![CDATA[<p dir="auto">Anyone running in the same issues?</p>
<p dir="auto">Best regards.</p>
]]></description><link>https://forum.qt.io/post/246139</link><guid isPermaLink="true">https://forum.qt.io/post/246139</guid><dc:creator><![CDATA[Korchkidu]]></dc:creator><pubDate>Fri, 03 Oct 2014 14:15:35 GMT</pubDate></item></channel></rss>