[Qt-interest] Does QGLWidget have to be manually released?

Donal O'Connor donaloconnor at gmail.com
Thu Oct 15 17:12:13 CEST 2009


Does you're sub class pass the parent widget pointer to the QGLWidget
superclass, QGLWidget?

Also, you don't have a constructor in your MyGLWidget that accepts a pointer
to a QWidget, not sure how it even compiles that way unless I'm missing
something.



On Thu, Oct 15, 2009 at 3:13 PM, Joe Liu <passer.by007gg at gmail.com> wrote:

> Hi guys,
>
> I am writing some OpenGL programs based on QGLWidget;
>
> My program now is quite simple, its structure is generally like this:
>
> ===========================================================
> *// my Qt gl widget class*
> class *MyGLWidget *: public QGLWidget
> {
>     MyGLWidget ();
>     ~MyGLWidget ();    // do nothing
>
>     // add some additional variables to manipulate the camera
> };
>
> *// my main window class*
> class *MyWindow *: public QMainWindow
> {
>     MyWindow(QWidget* parent);
>     ~QMainWindow();
>
>     MyGLWidget* m_pGLWindow;
> }
>
> *// how the GL widget is created and attached to the main window*
> MyWindow::MyWindow(QWidget* parent)
> : QMainWindow(parent)
> {
>     ui.setupUi(this);
>
>     *// set current main window as the parent of the gl widget***
>     m_pGLWindow = new MyGLWidget (this);   **
>     ui.glLayout->addWidget(m_pGLWindow);
> }
> ==================================================================
>
> At the beginning, everything works well; the GLWidget display a simple quad
> in the scene;
>
> However, when i tried to add more variables to help manipulate the camera
> states,
> The program always crashed when closing the application window;
>
> the compiler outputs the message: Heap block at 013AB9C8 modified at
> 013ABAE4 past requested size of 114
>
> Anyway, I tried to fix the problem by releasing QGLWidget object manually,
> in this way:
>
> ==================================================================
> MyWindow::~MyWIndow()
> {
>     m_pGLWindow->~MyGLWidget();  *// manually invoke the destructor of GL
> widget*
>
> *    // delete m_pGLWindow;  does not work*
> }
> ==================================================================
>
> Then the program shut down correctly.
>
> So does Qt GL widget have to be manually released? It's very weird...
>
> My Qt: v4.5.2,
> OS: Windows XP sp3
> Compiler: VC++ 9.0
>
> Need some help, thanks~~
>
> Cheers,
>
>
> Joe
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091015/51df12fd/attachment.html 


More information about the Qt-interest-old mailing list