[Interest] C'tor member initialisation with 'this'
Jan Kundrát
jkt at flaska.net
Fri Jan 10 20:35:56 CET 2014
The C++'s order of destruction is, in this case:
1) ~QtSoapHttpTransport(), which does more or less nothing. By the time it
returns, the object is no longer a QSHT (which is the reason why you must
not call virtual methods from destructors).
2) Any member variables are destroyed. In this case, one if them is a QNAM
which derives from QObject, so at some point the ~QObject() of the QNAM
runs, and at that time the QNAM is removed from the list of children of its
parent QObject, which is the former QSHT. This is safe, because
QSHT::~QObject has not run yet, so the former QSHT is still an QObject.
3) QSHT::~QObject runs, finally. It checks the list of its children, but
that list does not include the already destroyed QNAM, so the former QNAM
is not deleted twice and everything is OK.
Yup, took me some time to understand this as well -- thanks for ab
excellent question.
Cheers,
Jan
--
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/
More information about the Interest
mailing list