开发者

Qt application not exiting, staying in memory

开发者 https://www.devze.com 2023-01-07 10:45 出处:网络
Here is the code I am having trouble with: QApplication a(argc, argv); QString path = qApp->applicationDirPath();

Here is the code I am having trouble with:

QApplication a(argc, argv);
QString path = qApp->applicationDirPath();
qApp->setQuitOnLastWindowClosed(false);
a.addLibraryPath(path+"/plugins");
TryQt w;
w.show();
return  a.exec();

This is how I am starting my Application. In the Application (TryQt) I am creating several other QWidgets and Qwindows. The problem arises when I close the application The QMainWindow disappears, looks like the program exits, but it remains in the memory. (I can see from Task Manager / Processes ) . I am also catching the closeEvent in my TryQt program and closing every thing possible I opened in there. But still no use. Does 开发者_运维问答any one has any idea why this is happening?


well, it's because you're calling

qApp->setQuitOnLastWindowClosed(false);

the docs say:

This property holds whether the application implicitly quits when the last window is closed.

The default is true.

If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except for sub-windows. Refer to Qt::WindowType for a detailed list of Qt::Window objects.

and you are for some reason setting it to false.


I had a similar problem (except calling qApp->setQuitOnLastWindowClosed(true); as the previous answer suggests). I suspect one of the libraries we use doesn't clean up its thread properly and an investigation is pending, but the simplest workaround was to replace return a.exec(); with:

exit(a.exec());
0

精彩评论

暂无评论...
验证码 换一张
取 消