[Interest] How to properly delete qApp?

Nuno Santos nunosantos at imaginando.pt
Wed Mar 16 16:42:30 CET 2016


Nikos,

Thanks for your reply. 

The problems is that host application hangs forever if I don’t delete it and crashes if I delete it. I’m in a kind of dead end.

Any ideas?

Thanks

Nuno

> On 16 Mar 2016, at 14:07, Nikos Chantziaras <realnc at gmail.com> wrote:
> 
> On 16/03/16 14:01, Till Oliver Knoll wrote:
>> I don't think you're supposed to delete qApp
> 
> Actually you do need to delete it. Most people don't because after qApp->exec() returns, the program ends anyway. But if you want to have 0 leaks, you need to delete your QApplication instance.
> 
> Usually you don't delete qApp directly, but just your instance, but that's the same thing, really:
> 
>  int main(int argc, char** argv)
>  {
>      QApplication app = new QApplication(/* ... */);
>      app->exec();
>      delete app;
>      // or:
>      // delete qApp;
>      // which does the same thing.
>  }
> 
> In normal applications, like the above, deleting it is redundant. You're exiting the process, so the environment is going to clean your memory anyway. It's still a memory leak, if you're pedantic about it.
> 
> If you're using QApplication in a plugin, deleting qApp is actually mandatory, otherwise you're leaking the qApp instance when the plugin unloads; no one else is going to delete it for you.
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

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


More information about the Interest mailing list