How to make QOpenGLContext current without surface in Qt5?
<p>I am working on a project that will use OpenCL to render graphics for display in a <code>QOpenGLWidget</code>. The <a href="https://stackoverflow.com/questions/39542187/what-is-the-correct-way-to-get-opencl-to-play-nice-with-opengl-in-qt5/39556447?noredirect=1#comment66430421_39556447">recommended way</a> to do this seems to be creating a second <code>QOpenGLContext</code> beside the one already present in the <code>QOpenGLWidget</code>, then create a thread where this secondary context can live together with the OpenCL code.</p>

<p>This way Qt can go about it's day as usual with the eventloop running in the main thread. And whenever the <code>QOpenGLWidget</code> decides to paint it will simply fetch data from a buffer prepared in the second thread by the secondary context and the OpenCL inter-op set up there.</p>

<p>This all sounds great on paper, but I am having some problems getting this to work. My question is about how to make the secondary <code>QOpenGLContext</code> "current" in the thread. Because <code>QOpenGLContext::makeCurrent()</code> takes a mandatory <code>QSurface</code> as parameter, and the only surface I have is the one that is available from my <code>QOpenGLWidget</code>, but using that in the secondary thread does not work. I get the following error:</p>

<blockquote>
  <p>Cannot make QOpenGLContext current in a different thread</p>
</blockquote>

<p>So what surface should I use? Or, is there something I missed, or should do differently?</p>