Results 1 to 5 of 5

Thread: Calling function in a widget's destructor

  1. #1
    Join Date
    Nov 2012
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Calling function in a widget's destructor

    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.

  2. #2
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calling function in a widget's destructor

    What you are searching for is the QCloseEvent.
    Call the destroyVBO() method there and when it succeeds call accept() for closing

  3. #3
    Join Date
    Nov 2012
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Calling function in a widget's destructor

    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?

  4. #4
    Join Date
    Aug 2009
    Location
    Greece
    Posts
    69
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Calling function in a widget's destructor

    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
    Last edited by Rhayader; 5th December 2012 at 18:35. Reason: correction

  5. #5
    Join Date
    Nov 2012
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Calling function in a widget's destructor

    Works like a charm! Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 22nd November 2012, 05:03
  2. Calling external DLL function with Qt
    By yaba in forum Newbie
    Replies: 2
    Last Post: 29th September 2011, 07:47
  3. Replies: 2
    Last Post: 6th May 2011, 14:20
  4. Replies: 3
    Last Post: 25th April 2011, 03:40
  5. Replies: 2
    Last Post: 30th July 2010, 15:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.