Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to execute initialization method after QApplication::exec has been called?
Forum Update on Monday, May 27th 2025

How to execute initialization method after QApplication::exec has been called?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.2k 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.
  • J Offline
    J Offline
    Justin Sayne
    wrote on 20 Jul 2018, 13:23 last edited by
    #1

    I'm working with a very simple main method like this:

    int main()
    {
      MyQtApp app;
      return app.exec();
    }
    

    Lets assume my app has to do some very heavy initialization which should happen after application startup (especially without any user interaction to trigger). How can I achieve this?

    If I just do this:

    int main()
    {
      MyQtApp app;
      app.heavy_init();
      return app.exec();
    }
    

    then the even queue won't run and I can't emit signals. If I use a dedicated thread, it's still awkward because once the initialization is finished, I can't join the threads because the main thread will be executing QApplication::exec. Any ideas how to do what I'm looking for?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 20 Jul 2018, 13:27 last edited by
      #2

      Hi
      What about a single shot timer ?
      QTimer::singleShot(1000, { app.heavy_init(); } );

      1 Reply Last reply
      3

      1/2

      20 Jul 2018, 13:23

      • Login

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