title: Qt OpenGLFunctions seg fault
body: <p>I am trying to make a screengrabber using qt and QOpenGLFunctions. My code seg faults on funcs = context->functions(); This code is not really that great or threaded and the timers are not precise at such small intervals but it's more of a proof of concept thing than code I plan on using. As I understand I need to use these QOpenGLFunctions in order for it to be able to use ANGLE on windows. Which would help because windows only ships with opengl 1.0 and I'd rather not use that and use directx through ANGLE instead. I have tested on Ubuntu 16.04 LTS and Windows 10 using QT 5.5.1 through 5.7 on all the kits.</p>
  
  <p>Constructor:</p>
  
  <pre><code>MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
  {
  ui-&gt;setupUi(this);
  //QOpenGLContext *context = new QOpenGLContext();
  QOpenGLContext *context = QOpenGLContext::CurrentContext();
  //I only want to use glreadpixels. I don't need the rest of opengl. This may not be necessary. 
  QSurfaceFormat format;
  format.setRenderableType(QSurfaceFormat::OpenGL);
  format.setDepthBufferSize(32);
  format.setVersion(4,5);
  format.setSamples(4);
  format.setProfile(QSurfaceFormat::CompatibilityProfile);
  context-&gt;setFormat(format);
  context-&gt;create();
  
  funcs = context-&gt;functions(); //seg faults here
  funcs-&gt;initializeOpenGLFunctions();
  connect(timer, SIGNAL(timeout()), this, SLOT(grabScreen()));
  connect(timer2, SIGNAL(timeout()),this, SLOT(quit()));
  
  timer-&gt;setTimerType(Qt::PreciseTimer);
  timer2-&gt;setTimerType(Qt::PreciseTimer);
  timer2-&gt;start(10000); //10 sec
  timer-&gt;start(1000/60); //60 fps
  </code></pre>
  
  <p>}</p>
  
  <p>grabScreen:</p>
  
  <pre><code>void MainWindow::grabScreen()
  {
  //this method it too slow for anything more than one Monitor at 60 fps.
  //this-&gt;originalPixmap = this-&gt;primary-&gt;grabWindow(0,0,0,1920,1080);
  
  
  
  //this method is fast. Did 120 FPS no problem. It doesn't use the QtOpenGLFunctions. Less portable?
  //QImage image(1920,1080,QImage::Format_RGBA8888);
  //glReadPixels(0,0,1920,1080,GL_RGBA,GL_UNSIGNED_BYTE, image.bits());//not writing to the image bits
  
  QImage image(1920,1080,QImage::Format_RGBA8888);
  funcs-&gt;glReadPixels(0,0,1920,1080,GL_RGBA,GL_UNSIGNED_BYTE, image.bits());
  
  frameCount++;
  if(frameCount % 10 == 0) //update preview label
  {
      //ui-&gt;label-&gt;setPixmap(QPixmap::fromImage(image.scaled(ui-&gt;label-&gt;size())));
      ui-&gt;label-&gt;setPixmap(originalPixmap.scaled(ui-&gt;label-&gt;size()));
      //qDebug() &lt;&lt; QString("Frame: " + frameCount);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My other problem with this code is that for some reason the non qt glreadpixels does not write to the qimage.bits().</p>