As far as I know, this code should work:

Qt Code:
  1. void
  2. MyClass::draw()
  3. {
  4. if (this->pshader->isLinked()) {
  5. int val_loc = this->pshader->attributeLocation("val");
  6. this->pshader->setUniformValue(val_loc, (GLfloat)1.0);
  7. }
  8. // OpenGL stuff
  9. }
To copy to clipboard, switch view to plain text mode 

Vertex shader:

Qt Code:
  1. uniform float val;
  2.  
  3. varying float new_val;
  4.  
  5. void main()
  6. {
  7. new_val = val;
  8. gl_Position = ftransform();
  9. }
To copy to clipboard, switch view to plain text mode 

Fragment shader:

Qt Code:
  1. varying float new_val;
  2.  
  3. void main()
  4. {
  5. if (new_val < 0.5)
  6. gl_FragColor = vec4(1.0,0.0,0.0,1.0);
  7. else
  8. gl_FragColor = vec4(0.0,0.0,1.0,1.0);
  9. }
To copy to clipboard, switch view to plain text mode 

but my object appears red...