Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Shutdown of QT application in Web Assembly
Forum Updated to NodeBB v4.3 + New Features

Shutdown of QT application in Web Assembly

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
3 Posts 2 Posters 425 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GaryT
    wrote on 7 Feb 2023, 21:34 last edited by
    #1

    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

    J 1 Reply Last reply 8 Feb 2023, 07:25
    0
    • G GaryT
      7 Feb 2023, 21:34

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 8 Feb 2023, 07:25 last edited by jsulm 2 Aug 2023, 07:28
      #2

      @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;
      }
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GaryT
        wrote on 8 Feb 2023, 14:24 last edited by
        #3

        Thank you very much for taking the time to reply.
        Gary

        1 Reply Last reply
        0

        1/3

        7 Feb 2023, 21:34

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved