Skip to content

Commit

Permalink
Issue #119: use QCoreApplication::arguments() instead of argv[] to ha…
Browse files Browse the repository at this point in the history
…ve the proper encoding

(especially for Windows)
  • Loading branch information
mbruel committed Sep 29, 2021
1 parent ccfedc3 commit ceda375
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/NgPost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,22 +1215,24 @@ bool NgPost::hasMonitoringPostingJobs() const

bool NgPost::parseCommandLine(int argc, char *argv[])
{
QString appVersion = QString("%1_v%2").arg(sAppName).arg(sVersion);
Q_UNUSED(argc)
QString appVersion = QString("%1_v%2").arg(sAppName, sVersion);
QCommandLineParser parser;
parser.setApplicationDescription(appVersion);
parser.addOptions(sCmdOptions);


// Process the actual command line arguments given by the user
QStringList args;
for (int i = 0; i < argc; ++i)
args << argv[i];

bool res = parser.parse(args);
QStringList args = QCoreApplication::arguments();
if (!parser.parse(args))
{
#ifdef __DEBUG__
qDebug() << "args: " << args
<< "=> parsing: " << res << " (error: " << parser.errorText() << ")";
qDebug() << "cmd args: " << args;
#endif
_error(tr("Error syntax: %1\nTo list the available options use: %2 --help\n").arg(parser.errorText(), sAppName),
ERROR_CODE::ERR_WRONG_ARG);
return false;
}

if (parser.isSet(sOptionNames[Opt::QUIET]))
_quiet = true;
Expand Down Expand Up @@ -1261,13 +1263,6 @@ bool NgPost::parseCommandLine(int argc, char *argv[])
_dispFilesPosting = false;
}

if (!parser.parse(args))
{
_error(tr("Error syntax: %1\nTo list the available options use: %2 --help\n").arg(parser.errorText()).arg(argv[0]),
ERROR_CODE::ERR_WRONG_ARG);
return false;
}

if (parser.isSet(sOptionNames[Opt::LANG]))
{
QString lang = parser.value(sOptionNames[Opt::LANG]).toLower();
Expand Down

0 comments on commit ceda375

Please sign in to comment.