title: "shader program is not linked" when running QT hello opengl
body: <p>I have downloaded a QT OpenGL tutorial from <a href="http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf" rel="nofollow">http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf</a> and am trying to run the simplest example they have in there, which simply draws a triangle on top of a black background.</p>
  
  <p>I managed to compile the example, but when I run it, I only get a black window and the console reports the following:</p>
  
  <blockquote>
    <p>Starting
    /home/minas/Desktop/hello-opengl-build-Desktop_Qt_5_0_1_GCC_64bit-Debug/hello-opengl...
    QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not
    linked  QGLShaderProgram::uniformLocation( color ): shader program is
    not linked  QGLShaderProgram::attributeLocation( vertex ): shader
    program is not linked  QGLShaderProgram::attributeLocation( vertex ):
    shader program is not linked  QGLShaderProgram::attributeLocation(
    vertex ): shader program is not linked 
    QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not
    linked  QGLShaderProgram::uniformLocation( color ): shader program is
    not linked  QGLShaderProgram::attributeLocation( vertex ): shader
    program is not linked  QGLShaderProgram::attributeLocation( vertex ):
    shader program is not linked  QGLShaderProgram::attributeLocation(
    vertex ): shader program is not linked 
    QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not
    linked  QGLShaderProgram::uniformLocation( color ): shader program is
    not linked  QGLShaderProgram::attributeLocation( vertex ): shader
    program is not linked  QGLShaderProgram::attributeLocation( vertex ):
    shader program is not linked  QGLShaderProgram::attributeLocation(
    vertex ): shader program is not linked 
    QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not
    linked  QGLShaderProgram::uniformLocation( color ): shader program is
    not linked  QGLShaderProgram::attributeLocation( vertex ): shader
    program is not linked  QGLShaderProgram::attributeLocation( vertex ):
    shader program is not linked  QGLShaderProgram::attributeLocation(
    vertex ): shader program is not linked</p>
  </blockquote>
  
  <p>The .pro file looks like this (the "unix:!mac" part is my addition, so it finds the OpenGL .so files).</p>
  
  <pre><code>QT += core gui opengl
  
  TARGET = hello-opengl
  
  TEMPLATE = app
  
  SOURCES += main.cpp\
             glwidget.cpp
  
  HEADERS += glwidget.h
  
  OTHER_FILES += fragmentShader.fsh\
                 vertexShader.vsh
  
  RESOURCES += resources.qrc
  
  unix:!mac{
      QMAKE_LFLAGS += -Wl,--rpath=/usr/lib64/nvidia-current
      QMAKE_LFLAGS += -L/usr/lib64/nvidia-current
  }
  </code></pre>
  
  <p>The output of "glxinfo | grep -i opengl" is</p>
  
  <pre><code>OpenGL vendor string: NVIDIA Corporation
  OpenGL renderer string: GeForce 9800 GT/PCIe/SSE2
  OpenGL version string: 2.1.2 NVIDIA 304.64
  OpenGL shading language version string: (null)
  OpenGL extensions:
  </code></pre>
  
  <p>and the part of the code that does the actual rendering is</p>
  
  <pre><code>void GlWidget::paintGL()
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      QMatrix4x4 mMatrix;
      QMatrix4x4 vMatrix;
  
      // shaderProgram initialized in initializeGL()    
      shaderProgram.bind();
  
      // "mvpMatrix", "color" and "vertex" do exist in the shaders
  
      shaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
  
      shaderProgram.setUniformValue("color", QColor(Qt::white));
  
      shaderProgram.setAttributeArray("vertex", vertices.constData());
      shaderProgram.enableAttributeArray("vertex");
  
      glDrawArrays(GL_TRIANGLES, 0, vertices.size());
  
      shaderProgram.disableAttributeArray("vertex");
  
      shaderProgram.release();
  }
  </code></pre>
  
  <p>Also, as a side-question, why does the output of "glxinfo | grep -i opengl" contain the line</p>
  
  <blockquote>
    <p>OpenGL shading language version string: (null)</p>
  </blockquote>
  
  <p>(kinda seems relevant to me... is it?)</p>
  
  <hr>
  
  <h2>EDIT 1</h2>
  
  <p>The <code>shaderProgram</code> is declared in my subclass of <code>QGLWidget</code>, which I call <code>GLWidget</code> and initialized in <code>initializeGL</code> as such:</p>
  
  <pre><code>void GlWidget::initializeGL()
  {
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
  
      qglClearColor(QColor(Qt::black));
  
      shaderProgram.addShaderFromSourceFile(QGLShader::Vertex, ":/vertexShader.vsh");
      shaderProgram.addShaderFromSourceFile(QGLShader::Fragment, ":/fragmentShader.fsh");
      shaderProgram.link();
  
      vertices &lt;&lt; QVector3D(1, 0, -2) &lt;&lt; QVector3D(0, 1, -2) &lt;&lt; QVector3D(-1, 0, -2);
  }
  </code></pre>
  
  <hr>
  
  <h2>EDIT 2</h2>
  
  <p>Here is my initializeGL() method:</p>
  
  <pre><code>void GlWidget::initializeGL()
  {
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
  
      qglClearColor(QColor(Qt::black));
  
      shaderProgram.addShaderFromSourceFile(QGLShader::Vertex, ":/vertexShader.vsh");
      shaderProgram.addShaderFromSourceFile(QGLShader::Fragment, ":/fragmentShader.fsh");
      shaderProgram.link();
  
      vertices &lt;&lt; QVector3D(1, 0, -2) &lt;&lt; QVector3D(0, 1, -2) &lt;&lt; QVector3D(-1, 0, -2);
  }
  </code></pre>
  
  <p>and putting</p>
  
  <pre><code>qDebug() &lt;&lt; shaderProgram.log();
  exit(0);
  </code></pre>
  
  <p>immediately after the call to link() above does not produce any output.</p>