Thanks for the response! I just found this out earlier when going through the code here: http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qlayout.cpp and had it confirmed on the QtCentre forums.
I feel a bit daft actually. Thanks again, Steven On 14 March 2010 22:40, Coda Highland <[email protected]> wrote: > When the widget is added to the layout, it is automatically reparented > to the widget that owns the layout. There's no need for an explicit > setParent call because it's handled implicitly. > > /s/ Adam > > On Sun, Mar 14, 2010 at 1:16 PM, Steven Bakhtiari <[email protected]> > wrote: > > Hello! > > > > I was wondering if it would be possible to have the generated code from > > qt-creator pass a parent object into the constructor of promoted classes, > or > > rather, use the setParent method on the object, after instantiation? > > > > Scenario: > > > > I have a QStackedWidget object and each "page", or "layer", of the stack > has > > been promoted to a custom class, derived from QWidget. When adding > promoted > > classes through qt-creator, you define the superclass. > > > > On compilation some code is generated that builds the UI, however, the > > pages, or layers, of the QStackedWidget are not passed a parent object. > The > > code reads: > > > > QStackedWidget *sw = new QStackedWidget(mainWindowPointer); > > StackedLayer *foo = new StackedLayer(); > > > > instead of the preferable > > > > QStackedWidget *sw = new QStackedWidget(mainWindowPointer); > > StackedLayer *foo = new StackedLayer(stackedWidgetPointer); > > > > I feel this may cause some complications, say for example, if the custom > > class has a different constructor. For that reason, perhaps we should > call > > setParent after instantiation? For example: > > > > StackedLayer *foo = new StackedLayer(); > > foo->setParent(stackedWidgetPointer); > > > > The downside to not setting the parent means the developer needs to > > explicitly delete the object (please correct me if I'm wrong here, I'm > > pretty new to C++ & Qt) but they're not even explicitly instantiating the > > object, it all takes place in generated code, so this is confusing. It > means > > an app will likely have memory leaks. Also, it means objects that ideally > > should have a parent, don't. > > > > Perhaps there's a good reason that I'm unaware of for not doing this? > > > > Thanks for reading, > > > > Steven > > > > _______________________________________________ > > Qt-creator mailing list > > [email protected] > > http://lists.trolltech.com/mailman/listinfo/qt-creator > > > > > _______________________________________________ > Qt-creator mailing list > [email protected] > http://lists.trolltech.com/mailman/listinfo/qt-creator >
_______________________________________________ Qt-creator mailing list [email protected] http://lists.trolltech.com/mailman/listinfo/qt-creator
