PDA

View Full Version : Calling function in a widget's destructor



fiodis
5th December 2012, 17:48
I need to delete some OpenGL shader programs and VBOs. I need to do this before the OpenGL context itself is destroyed. The best way to do this is to call some destroyVBO() function when I click the big red X in the corner of my MainWindow, but before the QGLWidget's destructor is called. Is there any event that can capture that? glut and freeGLUT have glutCloseFunc. I don't know what the equivalent for Qt is.

Alternatively I guess I could reimplement the destructor for my QGLWidget. The trouble is, I don't know what I should put in it, aside from the destroyVBO() function. I would have to reimplement whatever is inside the base widget destructor, and I don't know what that does.

Rhayader
5th December 2012, 18:03
What you are searching for is the QCloseEvent.
Call the destroyVBO() method there and when it succeeds call accept() for closing

fiodis
5th December 2012, 18:26
That sounds perfect. When I click the X button, is the close event sent just to the MainWindow, which then calls each of its widgets' destructors, or is it sent to each widget seperately?

Rhayader
5th December 2012, 18:31
Just to the MainWindow. If you reject the event nothing more happens. If you accept it it calls the MainWindow's destructor if the Qt::WA_DeleteOnClose is set, else it just hides it

fiodis
5th December 2012, 18:54
Works like a charm! Thanks!