[Interest] Memory leak

Berkay Elbir berkayelbir at gmail.com
Fri Jun 12 15:52:20 CEST 2015

Hello all;

We recently joined a new project, which is full with idiom like: ,

void foo(){
    Widget* temp = new Widget;
    connect(temp, &Widget::signalTriggerred,[this, temp ]()
         do cool staff...

As you can see no delete nothing, I am afraid even user class "Widget" is
inherited QObject, this is still a leak. Does QT do something fancy to
prevent leek in case above?

What I am planning to do:

void foo {
     std::shared_ptr<Widget > temp( new Widget () );
     connect(temp.get(), &Widget::signalTriggerred,[this, temp] ()
          do even cooler things...

Is there a problem with my apporach? (For example I didn't want to use
.get() but compiler errors forced me to use it).

Thanks in advance,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150612/5c5c708e/attachment.html>

More information about the Interest mailing list