Results 1 to 2 of 2

Thread: QGLWidget deleted at startup

  1. #1
    Join Date
    Aug 2008
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGLWidget deleted at startup

    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

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGLWidget deleted at startup

    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.
    Last edited by d_stranz; 6th August 2012 at 21:58.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QGLWidget deleted at startup
    By tksharpless in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2012, 21:54
  2. QTextEdit not deleted when implemented as list
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 5
    Last Post: 24th June 2011, 07:46
  3. Makefile deleted automatically
    By raghvendramisra in forum Qt Tools
    Replies: 0
    Last Post: 6th May 2008, 06:24
  4. why bitBlt() deleted in Qt4
    By iGoo in forum Qt Programming
    Replies: 1
    Last Post: 27th June 2006, 09:59

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.