[Interest] C'tor member initialisation with 'this'

Frank Hemer frank at hemer.org
Fri Jan 10 18:42:30 CET 2014


On Friday 10 January 2014 20:51:35 Constantin Makshin wrote:
> Everything is OK unless QNetworkAccessManager's constructor (or anything
> further in the call chain) tries to use that pointer for anything beyond
> copying it somewhere else. What exactly is looking suspicious to you?

When the transports parent object gets deleted, it will delete the transport.
Thus I wonder whether it could cause a duplicate delete ('this' gets deleted 
and will subsequently delete the networkMgr but it is a member var and thus 
will be deleted twice?

Frank

> On Jan 10, 2014 5:32 PM, "Frank Hemer" <frank at hemer.org> wrote:
> > Hi,
> > 
> > when looking at the code of the qt solutions (from git), I realized
> > following
> > snippet:
> > 
> > class QT_QTSOAP_EXPORT QtSoapHttpTransport : public QObject
> > {
> > 
> >    ...
> > 
> > private:
> >     QNetworkAccessManager networkMgr;
> >    
> >    ...
> > 
> > };
> > 
> > QtSoapHttpTransport::QtSoapHttpTransport(QObject *parent)
> > 
> >     : QObject(parent), networkMgr(this)
> > 
> > {
> > 
> >    ...
> > 
> > }
> > 
> > Is there any reason why the QNetworkAccessManager needs to be initialized
> > with
> > the 'this' reference?
> > Seems like a wrong approach to me - maybe because it used to be a pointer
> > at
> > some point in time?
> > 
> > I found this when analyzing some weird and not really reproducible stack
> > traces ...
> > 
> > Frank
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list