How to enable depth test with QOpenGLWidget? It renders black screen
<p>Currently I am writing a small application with Qt and OpenGl and I choosed <code>QOpenGLWidget</code> for rendering graphics.</p>

<p>That's how I declared my widget:</p>

<pre><code>class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions{
     // Methods, slots, e.t.c
}
</code></pre>

<p>And that's the constructor:</p>

<pre><code>GLWidget::GLWidget(QWidget *parent) : QOpenGLWidget(parent)
{
    /* Tried this, it didn't help.
    QSurfaceFormat format;
    format.setDepthBufferSize(24);
    this-&gt;setFormat(format);
    */
}
</code></pre>

<p>In my init function I set <code>GL_CULL_FACE</code> and <code>GL_DEPTH_TEST</code>:</p>

<pre><code>void GLWidget::initializeGL()
{
    /* Some initialization stuff regarding the scene */

    glEnable(GL_CULL_FACE);
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

}
</code></pre>

<p>And I really don't know why the widget renders the black screen.
Here are some pictures.
First one: with disabled <code>GL_CULL_FACE</code> and disabled <code>GL_DEPTH_TEST</code>.
<a href="https://i.stack.imgur.com/YWgne.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YWgne.png" alt="enter image description here"></a></p>

<p>Second one: with enabled <code>GL_CULL_FACE</code> and disabled <code>GL_DEPTH_TEST</code>. Maybe it's not a good picture, but I can assure you, you can see some surfaces through the other.
<a href="https://i.stack.imgur.com/NWLNU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NWLNU.png" alt="enter image description here"></a></p>

<p>Third one: with enabled <code>GL_CULL_FACE</code> and enabled <code>GL_DEPTH_TEST</code>. Actually, it doesn't matter if <code>GL_CULL_FACE</code> is enabled. Anyway it renders the black screen.
<a href="https://i.stack.imgur.com/YSQiE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YSQiE.png" alt="enter image description here"></a></p>

<p>And here's the image without any shading just to show you that the model is fine.
<a href="https://i.stack.imgur.com/Fvx9m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fvx9m.png" alt="enter image description here"></a></p>

<p>I tried to set the format manually, but it didn't help. Still the black screen:</p>

<pre><code>QSurfaceFormat format;
format.setDepthBufferSize(24);
this-&gt;setFormat(format);
</code></pre>

<p>Oh and yes, I set <code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</code> at the beginning of my <code>paintGL()</code> function.</p>