I'm attempting to draw a triangle to a (derived) QGLWidget, using Qt 5.2 on an Arch Linux system. I've found that if I try to set the version to anything greater than 2.1, I don't get a drawing. Here's my source:

Qt Code:
  1. #include <QtOpenGL>
  2. #include <QGLContext>
  3. #include <QGLFormat>
  4. #include <QGLShader>
  5. #include <QGLShaderProgram>
  6.  
  7. #include <QDebug>
  8.  
  9. #include "GLWidget.h"
  10.  
  11.  
  12. GLWidget::GLWidget(QWidget *parent, const QGLWidget *shareWidget, Qt::WindowFlags f)
  13. : QGLWidget(parent, shareWidget, f)
  14. {
  15. QGLFormat newFormat(format());
  16.  
  17. /* Change to 3.0 and no triangle is drawn */
  18. newFormat.setVersion(2,1);
  19. setFormat(newFormat);
  20.  
  21. makeCurrent();
  22. }
  23.  
  24. void GLWidget::initializeGL()
  25. {
  26. _backgroundColour = Qt::black;
  27. _triangleColour = Qt::white;
  28. _triangle.push_back(QVector3D(-0.75, 0.75, 0));
  29. _triangle.push_back(QVector3D(-0.75, -0.75, 0));
  30. _triangle.push_back(QVector3D(0.75, -0.75, 0));
  31. }
  32.  
  33. void GLWidget::paintGL()
  34. {
  35. qglClearColor(_backgroundColour);
  36. glClear(GL_COLOR_BUFFER_BIT);
  37.  
  38. glEnableClientState(GL_VERTEX_ARRAY);
  39. glVertexPointer(3, GL_FLOAT, 0, _triangle.constData());
  40. glDrawArrays(GL_TRIANGLES, 0, 3);
  41. }
  42.  
  43. void GLWidget::resizeGL(int width, int height)
  44. {
  45. int side = qMin(width, height);
  46.  
  47. int hoffset = (int)((width - side) / 2.0 + 0.5);
  48. int voffset = (int)((height - side) / 2.0 + 0.5);
  49.  
  50. glViewport(hoffset, voffset, side, side);
  51. }
To copy to clipboard, switch view to plain text mode 

I've tried using the alternate constructor that takes a QGLFormat object, and I get the same effect. Interestingly, if I dump the output of format() to qDebug() (inside GLWidget::initializeGL()), it says it's using version 3.0.

Second issue... if I give up on explicitly setting the OpenGL version, but try to compile shaders with "#version 300", I get the following error:

QGLShader::compile(Vertex): 0:1(10): error: GLSL 3.00 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.00 ES, and 3.00 ES
I'm calling the function that creates and compiles my shaders from GLWidget::initilizeGL(), immediately after dumping the format string to qDebug(), so I know I've got OpenGL 3.0. What's going on?

To summarize:

1. How can I explicitly set the OpenGL version?
2. Why does QGLShader seem to think my OpenGL version is older than what QGLWidget thinks it is?