[Qt-creator] feature request: have qt-creator set a parent for promoted classes on instantiation

Steven Bakhtiari steven.bakh at gmail.com
Sun Mar 14 19:16:04 CET 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-creator-old/attachments/20100314/7523a3f0/attachment.html 


More information about the Qt-creator-old mailing list