I am new at OpenGL, I try this example:  http://stackoverflow.com/a/31524956/4564882



but I get only a black widget. The code is exactly the same. this is the code associated to the QopenGLWidget:

    OGLWidget::OGLWidget(QWidget *parent)
    : QOpenGLWidget(parent)
     {

     }

     OGLWidget::~OGLWidget()
    {

    }

     void OGLWidget::initializeGL()
     {
       glClearColor(0,0,0,1);
       glEnable(GL_DEPTH_TEST);
       glEnable(GL_LIGHT0);
       glEnable(GL_LIGHTING);
       glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
       glEnable(GL_COLOR_MATERIAL);
    }

     void OGLWidget::paintGL()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBegin(GL_TRIANGLES);
        glColor3f(1.0, 0.0, 0.0);
        glVertex3f(-0.5, -0.5, 0);
        glColor3f(0.0, 1.0, 0.0);
        glVertex3f( 0.5, -0.5, 0);
        glColor3f(0.0, 0.0, 1.0);
        glVertex3f( 0.0,  0.5, 0);
    glEnd();
     }

     void OGLWidget::resizeGL(int w, int h)
     {
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45, (float)w/h, 0.01, 100.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,5,0,0,0,0,1,0);
      }


I tried the example here: https://doc.qt.io/archives/qt-5.3/qtopengl-2dpainting-example.html. It works fine (trying the both base class: QGLWidget and QOpenGLWidget. this is the code associated to the Widget:

      GLWidget::GLWidget(Helper *helper, QWidget *parent)
      : QGLWidget(QGLFormat(QGL::SampleBuffers), parent), helper(helper)
     {
     elapsed = 0;
    setFixedSize(200, 200);
    setAutoFillBackground(false);
    }

    void GLWidget::animate()
    {
     elapsed = (elapsed + qobject_cast<QTimer*>(sender())->interval()) % 1000;
     repaint();
     }

    void GLWidget::paintEvent(QPaintEvent *event)
    {
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);
    helper->paint(&painter, event, elapsed);
    painter.end();
    }

I use  Qt 5.5.1 binairies built on my machine. I let the Build Configuration by default, so it is based on Qt ANGLE not Desktop OpenGL.
My Graphic card Driver is updated.
What is the problem of such a behaviour?