Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QCoreApplication::exec()
Forum Updated to NodeBB v4.3 + New Features

QCoreApplication::exec()

Scheduled Pinned Locked Moved Solved C++ Gurus
3 Posts 2 Posters 879 Views 1 Watching
  • 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #1

    One could debate whether this question belongs in C++ Gurus sub-forum, but here it is anyway.

    What exactly does QCoreApplication::exec() do, and what does it wait for?

    I start with a "minimal" Qt Creator Console Application:

    #include <iostream>
    
    #include <QCoreApplication>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        std::cout << "Hello world!" << std::endl;
    
        return a.exec();
    }
    

    I guess the a.exec() is waiting for quit() to be called, through a signal or similar? Not much else for a console application to wait for....

    So if I want a really console-type Hello world program, which prints it and then exits, I might as well omit the a.exec() here? At the moment code does not use any Qt functionality; if it did, would failing to run QCoreApplication::exec() have any adverse effects, e.g. would some Qt things fail to get cleaned up properly?

    jsulmJ 1 Reply Last reply
    0
    • JonBJ JonB

      One could debate whether this question belongs in C++ Gurus sub-forum, but here it is anyway.

      What exactly does QCoreApplication::exec() do, and what does it wait for?

      I start with a "minimal" Qt Creator Console Application:

      #include <iostream>
      
      #include <QCoreApplication>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          std::cout << "Hello world!" << std::endl;
      
          return a.exec();
      }
      

      I guess the a.exec() is waiting for quit() to be called, through a signal or similar? Not much else for a console application to wait for....

      So if I want a really console-type Hello world program, which prints it and then exits, I might as well omit the a.exec() here? At the moment code does not use any Qt functionality; if it did, would failing to run QCoreApplication::exec() have any adverse effects, e.g. would some Qt things fail to get cleaned up properly?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @JonB said in QCoreApplication::exec():

      a.exec()

      It starts the Qt event loop. If you do not need event loop do not call exec.

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

      JonBJ 1 Reply Last reply
      2
      • jsulmJ jsulm

        @JonB said in QCoreApplication::exec():

        a.exec()

        It starts the Qt event loop. If you do not need event loop do not call exec.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @jsulm Good to know there aren't any significant "gotchas" for this simple case, thanks.

        1 Reply Last reply
        0
        • JonBJ JonB has marked this topic as solved on

        • Login

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