[Interest] Advice on random program finish crash

Michael Sué sue at sf.mpg.de
Wed Jan 7 13:58:26 CET 2015


Hi,

Our application main program looks (essentially) like the following:

int main(int argc, char *argv[])
{
	MyApplication app(argc, argv);
	MyMainWindow mainWin();
	return app.exec();
}

We create the one and only network access manager object in the constructor of MyMainWindow (with new QNetworkAccessManager(this)) and destroy it in its destructor (with a simple delete). It should also work if you do it in MyApplication, or using a factory like you are about to do it. But maybe it's better if you define a release function as well that deletes the object and explicitly call it by yourself.

- Michael.


From: Nuno Santos [mailto:nunosantos at imaginando.pt] 
Sent: Wednesday, January 07, 2015 1:37 PM
To: Michael Sué
Cc: igor.mironchik at gmail.com; interest at qt-project.org
Subject: Re: [Interest] Advice on random program finish crash

Hi,

I’m not really sure. 

Question: 

- On program termination, isn’t all the memory allocated by it deleted?

With this approach at least the QNetworkAccessManager which is being allocated by the manager is supposedly being deleted:

Manager::~Manager()
{
    _networkAccessManager->deleteLater();
}

Which is called if I set app as Manager parent.

I’m not sure if this will result in a successful object deletion since the event loop is now terminated at this point.

While without any crash, i’m always looking to improve my understanding of this low level details. Any ideas, suggestions or explanations are welcome.

Thanks,

Regards,

Nuno





More information about the Interest mailing list