[Interest] Moving to smart pointers: recommendations

Scott Aron Bloom scott.bloom at onshorecs.com
Tue Apr 9 17:34:02 CEST 2013


If you are working with QObject based objects, that are not "parentless" I personally still recommend new/delete just making sure the parent is set.

I use smartpointers for the "top" widgets/objects ie anything that doesn't have a parent, as well as any NON Qobject based pointers.

For instance, all "ui" created classes, rather than a new/delete are smart pointers constructed during the construction of the actual widget/object.

Scott

-----Original Message-----
From: interest-bounces+scott.bloom=onshorecs.com at qt-project.org [mailto:interest-bounces+scott.bloom=onshorecs.com at qt-project.org] On Behalf Of Sensei
Sent: Tuesday, April 9, 2013 8:22 AM
To: interest at qt-project.org
Subject: [Interest] Moving to smart pointers: recommendations

Dear all,

after years of new/delete, I am ready to give smart pointers a try. But I'm quite puzzled about their implementation after reading the awesome "tutorial" (*) by Thiago Macieira.

As an example, I ask you guys some recommendations on practical examples.


Let's say I am creating some QActions. Right now I'm using a QList<QAction*>, and in my destructor I delete them. Is here possible to use only a QPointer?


If I'm dealing with my internal widgets in a QMainWindow, is it recommended a QSharedPointer?


Thanks for clarifying these doubts!


(*) 
http://blog.qt.digia.com/blog/2009/08/25/count-with-me-how-many-smart-pointer-classes-does-qt-have/
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list