[Interest] QCommandLineParser, default arguments from env variable?

Mark Gaiser markg85 at gmail.com
Mon Jun 23 14:18:35 CEST 2014


Hi,

Qt 5.2 introduced the rather nice QCommandLineParser class. It seems
to have every feature one can wish for yet i somehow seem to be
missing one small tiny feature :)

Some applications (daemons mostly) allow features like setting all
default arguments via an environment variable which would then be
overridden if the app specifically provided an argument. An example of
how that would work:

// Environment var
APP_ARGS = --something value --anotherthing value

Now if you would start the app without providing any arguments it
would still have some default arguments which would read:
- something -> value
- anotherthing -> value

Now if you would start the same app with: <start_app> --something qtproject
Would give you the arguments:
- something -> qtproject
- anotherthing -> value

I know that you can set the default arguments in code with
QCommandLineOption and that works rather well. But i miss (or am i
overlooking it?) an option to set default arguments via a command line
define.

It would be cool if QCommandLineParser would always look for a
<APPNAME_ARGS> environment variable.

So, is this possible in the current code? Since i couldn't find anything.

Cheers,
Mark



More information about the Interest mailing list