Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QOpenGLWidget - context - nullptr! :- (



  • Hey

    This is one of the precious ones...

    So I have a

    h. myGL
    
    class myGL:public QOpenGLWidget, public QOpenGLFunctions, public render{
         myGL(buffer)
    }
    /// this class has normal cpp/with overloaded paintGL/initializeGL(with     initializeOpenGLFunctions();)/resizeGL
    //// paintGL class emits signal to a buffer with new image painted. <- since I want to be able to display 1 GL buffer in different widgets. I figures this is the way to go ?
    
    
    cpp. myWrapper
    
    void myWrapper:makeBuffer(){
         mBuffer = buffer() ; /// << This displays the rendered image by openGLWidget
         myGL = std::shared_ptr<myGL>(mBuffer); ////<< shared ptr because I add it to buffer list and I have different render engines, Raytracers/gl/etc/etc so its a generic base class/form of storage... not sure how QT react to it, do I need to new it somehow ? no idea...
    
         scene() - > addRenderToNodes(myGL) ; //// < tells all nodes in a scene to add them self to a render. The base class is render.  - each node essentially call render->registerNode(this) (its a little more complex but this simplified is fine to show here I think)  In any case what happens is the myGL object then gets called registerNode() which checks what nodes is and then create proper openGL node, so if its geometry it would make glNodeGeometry(node)  - and here is the problem ! > 
    

    Esentially what I can tell is when I do qDebug()<< context(), when myGL class is made, the result is null. and when scene()->addRenderToNodes() gets called with the render and nodes try to add themself in, it crashes because there is no context.

    As far as I can tell the context does not get made untill the widget is displayed in QT... or something like that... can any1 help how to force creation of context or something? I'm lost here :- (



  • Do you have opengl installed and drivers which support it? Otherwise Qt cannot grab a context for you.



  • Yes all installed & running. I have another test app that runs just fine. But this one is so weird... whhh

    I ended up installing a Qt::Concurrent and then running a while(!myGL()->context()) test loop before firing the addRenderToNodes() function. That somehow works but mmmm



  • @Dariusz said in QOpenGLWidget - context - nullptr! :- (:

    As far as I can tell the context does not get made untill the widget is displayed in QT... or something like that

    This is correct. And it's why the initalizeGL function is separate from the constructor - you can't run OpenGL stuff in the constructor. You have to defer all of that until after the context is created in initializeGL. If you previously made some QOpenGWidget, it might have a separate context, so even if it appears to work, you'll wind up setting things up for the wrong context if you do it in the constructor.

    You can't really do anything sensible with a QOpenGLWidget that isn't visible yet anyway. You can't see anything that you would try to draw into it!


Log in to reply