PDA

View Full Version : QGLWidget deleted at startup



tksharpless
6th August 2012, 21:43
I regularly use subclasses of QGLWidget as the central widget in a QMainWindow. But now I have one that somehow is getting deleted -- not by my code -- at program startup. The main window ctor creates the widget apparently OK, and it still look OK when its resize handler gets called (as expected) when main() issues show() for main window; but as soon as main calls app.exec() its dtor gets called with a deferred_delete message.

The class in question is an elaboration of one I have used sucessfully in another program, so I guess the problem has to do with something I changed. I'm gradually rolling back those changes but have not yet found the critical one.

But what I want to ask here is the general question: has anyone heard of a QGLWidget deleting itself? Or know why the meta-object or window system might do that?

Thanks, Tom

d_stranz
6th August 2012, 22:48
Did you perhaps call setCentralWidget() with a different widget instance (or inadvertently by way of a .ui or QML)? Or did you accidentally declare a QGLWidget * as a local variable within QMainWindow ctor, overriding a member variable in the QMainWindow class?

Edit (from duplicated thread):


FIXED by moving create/install QGLWidget after GUI setup in MainWindow c'tor. A C++ problem I guess.


Probably not a C++ problem. You should call setupUi() first in the constructor, before any other Qt initialization. If you instantiate Qt widgets as children of the MainWindow before calling setupUi, these will probably be deleted when setupUi does its thing. If you are creating a custom widget to serve as the central widget in a MainWindow class, you should do that replacement after setupUi is done.