title: 2 QOpenGLWidget shared context causing crash
body: <p>I would like to solve problem that I still deal with.. thats render 2 QOpenGLWidgets at same time in different top level windows with shared shader programs etc.</p>
  <p>My first attempt was to use one context, wasnt working.</p>
  <p>Is it even possible currently with QOpenGLWidget? Or I have to go to older QGLWidget? Or use something else?</p>
  <p>testAttribute for Qt::AA_ShareOpenGLContexts returns true so there is not problem with sharing
  even QOpenGLContext::areSharing returns true. So there is something I missing or I dont know. Not using threads.</p>
  <p>Debug output:</p>
  <blockquote>
  <p>MapExplorer true true true QOpenGLShaderProgram::bind: program is not
  valid in the current context. MapExlorer paintGL ends MapExplorer true
  true true QOpenGLShaderProgram::bind: program is not valid in the
  current context. MapExlorer paintGL ends
  QOpenGLFramebufferObject::bind() called from incompatible context
  QOpenGLShaderProgram::bind: program is not valid in the current
  context. QOpenGLShaderProgram::bind: program is not valid in the
  current context. QOpenGLShaderProgram::bind: program is not valid in
  the current context. QOpenGLFramebufferObject::bind() called from
  incompatible context QOpenGLFramebufferObject::bind() called from
  incompatible context</p>
  </blockquote>
  <p>MapView initializeGL:</p>
  <pre><code>void MapView::initializeGL()
  {
      this-&gt;makeCurrent();
  
      initializeOpenGLFunctions();
  
      // Initialize World
      world-&gt;initialize(this-&gt;context(), size(), worldCoords);
  
      // Initialize camera shader
      camera-&gt;initialize();
  
      // Enable depth testing
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
  
      glDepthFunc(GL_LEQUAL); // just testing new depth func
  
      glClearColor(0.65f, 0.77f, 1.0f, 1.0f);
  }
  </code></pre>
  <p>MapView paintGL:</p>
  <pre><code>void MapView::paintGL()
  {
      this-&gt;makeCurrent();
  
      glDrawBuffer(GL_FRONT);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      world-&gt;draw(...);
  }
  </code></pre>
  <p>MapExplorer initializeGL:</p>
  <pre><code>void MapExplorer::initializeGL()
  {
      this-&gt;makeCurrent();
  
      QOpenGLContext* _context = _mapView-&gt;context();
      _context-&gt;setShareContext(this-&gt;context());
      _context-&gt;create();
  
      this-&gt;context()-&gt;create();
      this-&gt;makeCurrent();
  
      initializeOpenGLFunctions();
  
      // Enable depth testing
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
  
      glDepthFunc(GL_LEQUAL); // just testing new depth func
  
      glClearColor(0.65f, 0.77f, 1.0f, 1.0f);
  }
  </code></pre>
  <p>MapExplorer paintGL:</p>
  <pre><code>void MapExplorer::paintGL()
  {
      this-&gt;makeCurrent();
  
      qDebug() &lt;&lt; &quot;MapExplorer&quot; &lt;&lt; QOpenGLContext::areSharing(this-&gt;context(), _mapView-&gt;context()) &lt;&lt; (QOpenGLContext::currentContext() == this-&gt;context());
  
      QOpenGLShaderProgram* shader = world-&gt;getTerrainShader();
      qDebug() &lt;&lt; shader-&gt;create();
      shader-&gt;bind(); // debug error &quot;QOpenGLShaderProgram::bind: program is not valid in the current context.&quot;
  
      // We need the viewport size to calculate tessellation levels and the geometry shader also needs the viewport matrix
      shader-&gt;setUniformValue(&quot;viewportSize&quot;,   viewportSize);
      shader-&gt;setUniformValue(&quot;viewportMatrix&quot;, viewportMatrix);
  
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      qDebug() &lt;&lt; &quot;MapExlorer paintGL ends&quot;;
  
      //world-&gt;drawExplorerView(...);
  }
  </code></pre>