title: QOpenGLWidget with QApplication?
body: <p>We have a QWidget based application that was previously using a QWindow for OpenGL rendering. To fit that window in our application we had to use </p>
  
  <pre><code>QWidget QWidget::createWindowContainer(QWindow);
  </code></pre>
  
  <p>Previously we only used external to Qt OpenGL libraries for rendering.</p>
  
  <p>We have a desire to switch from using QWindow to some kind of QWidget for compatibility with touch gestures, and generally better overall compatibility with the rest of our application. The latest recommended OpenGL compatible QWidget seems to be QOpenGLWidget, so we are trying to use that.</p>
  
  <p><code>glContext</code> is an OpenGLContext that we manage ourselves.</p>
  
  <p>The problem now is that QOpenGLWidget is not a QSurface, so I cannot call</p>
  
  <pre><code>glContext-&gt;makeCurrent(this);
  </code></pre>
  
  <p>to make the context current on my custom QOpenGLWidget like we could before with our custom QWindow and our own OpenGLContext.</p>
  
  <p>If I try to use <code>QOpenGLWidget::makeCurrent();</code> then this uses the wrong context and tries to do stuff with some magical QT handled context or something I don't understand.</p>
  
  <p>The result is that after creating our OpenGLContext when we try to call </p>
  
  <pre><code>glFunctions = glContext-&gt;versionFunctions&lt;QOpenGLFunctions_3_3_Core&gt;();
  if(!glFunctions-&gt;initializeOpenGLFunctions())
    printf("Could not initialize OpenGL functions.");
  </code></pre>
  
  <p>It always fails to initialize the OpenGL functions.</p>
  
  <p>I have been reading over all the other resources I can find on the subject and came across this older Stack Overflow question that was similar:
  <a href="https://stackoverflow.com/questions/33635001/qopenglwidget-with-shared-opengl-context">QOpenGLWidget with shared OpenGL context?</a></p>
  
  <p>The answer to that question did not solve my issue because we are using QApplication, not QGuiApplication as this is a QWidget based application.
  <code>QGuiApplicationPrivate::init()</code> is never called and the <code>QOpenGLContext::globalShareContext()</code> returns a null pointer since it is not initialized.</p>
  
  <p>Unfortunately I cannot wait for <code>QOpenGLWidget::initializeGL()</code> to be called to initialize the QT managed <code>OpenGLContext</code> since we already have lots of OpenGL resources over various classes that <em>attempt</em> to get initialized before that.</p>
  
  <p>Has anyone else come across this same problem?</p>
  
  <p>Any suggestions?</p>