Even though the graphical user interface is a big selling point of the Qt framework, it is also possible to use it to develop command-line-only applications. For this, we just use the QCoreApplication class to create an input and an event loop handler, as in this example:
#include <QCoreApplication> #include <core.h> int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); Core core; connect(&core, &Core::done, &app, &app::quit, Qt::QueuedConnection); core.start(); return app.exec(); }
Here, our code is implemented in a class called Core. In the main function, we create a QCoreApplication instance, which receives the command-line parameters. We then instantiate an instance of our class.
We connect a signal from our class to the QCoreApplication instance, so that if we signal that...