PDA

View Full Version : Must the QGLWidget::makeCurrent () be called inside of the constructor?



superwave
27th June 2011, 15:59
Must the QGLWidget::makeCurrent () be placed inside of the constructor?

such as:

QGLWidget::QGLWidget(QWidget *parent)
{
......
makeCurrent();
......
glBegin(GL_LINES);
glVertex3f(+1.0, +1.0, -1.0);
...
}

I tried this:

QGLWidget *canvas;
...
canvas->makeCurrent();
......
glBegin(GL_LINES);
glVertex3f(+1.0, +1.0, -1.0);
...

However, in this way, it's blank, nothing is shown on the QGLWidget.

stampede
27th June 2011, 21:37
You should wait with the OpenGL calls until initializeGL(), what if OpenGL context of existing widget changes, or someone creates your widget and call "setContext" later ? In that case, you'll end up with incorrectly initialized widget if you rely on constructor initialization.
To answer your question - yes, it must be called, but it's not reliable.