From b7beced1e5ce13bc8618b7d334c852ca86b39273 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Wed, 30 Jan 2019 08:53:19 +0100 Subject: [PATCH] Parse command line options platform (and encoding) independent --- source/ESGRAF48.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/source/ESGRAF48.cpp b/source/ESGRAF48.cpp index 1f15804..40b8801 100644 --- a/source/ESGRAF48.cpp +++ b/source/ESGRAF48.cpp @@ -1,18 +1,31 @@ #include "mainwindow.h" #include +#include int main(int argc, char **argv) { QApplication app(argc, argv); + QCoreApplication::setApplicationName("ESGRAF 4-8"); + QCoreApplication::setApplicationVersion("0.1"); + + QCommandLineParser cmdParser; + cmdParser.setApplicationDescription("ESGRAF 4-8"); + cmdParser.addHelpOption(); + cmdParser.addVersionOption(); + cmdParser.addPositionalArgument("filename", "file to open"); + + cmdParser.process(app); + + const QStringList args = cmdParser.positionalArguments(); std::unique_ptr mainWindow; - if (argc < 2) + if (args.empty()) { mainWindow = std::make_unique(nullptr); } else { - mainWindow = std::make_unique(nullptr, argv[1]); + mainWindow = std::make_unique(nullptr, args.at(0)); } mainWindow->show();