#include#include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setApplicationName("MyApp"); app.setApplicationVersion("1.0"); QCommandLineParser parser; parser.addVersionOption(); parser.process(app); return 0; }
#includeIn this example, we create a new QCommandLineParser object, add a custom version number and description, and process the command line arguments. If the version option is set, we output the name and version of the application using qDebug(). The QCommandLineParser class is part of the Qt Core module.#include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); app.setApplicationName("MyApp"); QCommandLineParser parser; parser.addVersionOption("2.0", "MyApp 2.0"); parser.process(app); if (parser.isSet(QCommandLineOption::Version)) qDebug() << qPrintable(app.applicationName()) << " version " << qPrintable(app.applicationVersion()); return 0; }