I have a class named Mesh which wraps and OpenGL object, with VBO, texture, etc. This class inherits from QObject and its parent is set to my QGLWidget. So as soon I close the widget it will get deleted by QObject system.
But I have a problem because this mesh class has a destructor that does some OpenGL calls to cleanup. When QObject child destructor kicks in, the OpenGL context is already destroyed and I get a segfault.
How I can make sure that my ~Mesh() destructor will get called before QGLWidget context gets deleted?