QCoreApplication::exec()
-
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 forquit()
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 runQCoreApplication::exec()
have any adverse effects, e.g. would some Qt things fail to get cleaned up properly? -
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 forquit()
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 runQCoreApplication::exec()
have any adverse effects, e.g. would some Qt things fail to get cleaned up properly?@JonB said in QCoreApplication::exec():
a.exec()
It starts the Qt event loop. If you do not need event loop do not call exec.
-
@JonB said in QCoreApplication::exec():
a.exec()
It starts the Qt event loop. If you do not need event loop do not call exec.
-
J JonB has marked this topic as solved on