Wrapping a QOpenGLWidget in a QAbstractScrollArea
-
When I set a subclass of QOpenGLWidget as the viewport to a QAbstractScrollArea it seems a lot of the initialization for the widget does not happen.
I have two classes
class ScrollCanvas : public QAbstractScrollArea
and
class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
ScrollCanvas
has a GLWidget as a member and I set it to the viewport usingsetViewport(glWidget);
In QAbstractScrollArea there is a function
setupViewport
where I can initialize the viewport after it's set. In this function I callinitializeGL()
from GLWidget. However the call toinitializeOpenGLFunctions();
, which is the first thing ininitializeGL()
causes a crash. I put a print statement just above this line and printed the address of the QOpenGLContext and found that it was set to 0.When the GLWidget is not set as the viewport of the QAbstractScrollArea the QOpenGLContext has a valid memory address at this point. So it seems that a function is not being called during the initialization of the widget. Can anyone tell me what initialization needs to occur before
initializeGL()
such that the QOpenGLContext is valid?