Shutdown of QT application in Web Assembly
-
When I close the browser tab that my QT application runs in, the QApplication object is not deleted. According to the documentation, this problem can be resolved by rewriting the main program as follows :
QApplication *g_app = nullptr;
AppWindow *g_appWindow = nullptr;int main(int argc, char **argc)
{
g_app = new QApplication(argc, argv);
g_appWindow = new AppWindow();
return 0;
}It further states that the application can be shut down by deleting the application object and the main window. I was wondering where the best place would be to do the deletes as the documentation does not suggest a place.
Thanks
Gary -
@GaryT said in Shutdown of QT application in Web Assembly:
g_app = new QApplication(argc, argv);
There is absolutelly no need to allocate QApplication and AppWindow on the heap!
int main(int argc, char **argc) { QApplication g_app(argc, argv); AppWindow g_appWindow; g_appWindow.show(); return g_app.exec(); }
If you reall need to do it with heap allocation then do it like this:
QApplication *g_app = nullptr; AppWindow *g_appWindow = nullptr; int main(int argc, char **argc) { g_app = new QApplication(argc, argv); g_appWindow = new AppWindow(); g_appWindow->show(); auto result = g_app->exec(); delete g_appWindow; delete g_app; return result; }