[Qt-creator] feature request: have qt-creator set a parent for promoted classes on instantiation
Coda Highland
coda at bobandgeorge.com
Sun Mar 14 23:40:43 CET 2010
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 <steven.bakh at gmail.com> 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
> Qt-creator at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-creator
>
>
More information about the Qt-creator-old
mailing list