PDA

View Full Version : Change usage information that comes by default with QCommandLineParser class



varun1312
9th March 2016, 14:54
I am working on a simple command line parser using QCommandLineParser class(Qt Version 5.4.0). Below is the code:



#include <QCommandLineOption>
#include <QCommandLineParser>
#include <QCoreApplication>
#include <QDebug>
#include <QString>
#include <QStringList>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
parser.process(app);
return 0;
}

When I execute the program, I see the following output

>./firstCommandLineParser --help
Usage: ./firstCommandLineParser [options]

Options:
-h, --help Displays this help.
The format of usage information displayed contains only [options] and additionally I can specify positional arguments with addPositionalArgument method.

However, I want to see the usage information displayed in the following format:

Usage: ./firstCommandLineParser [-d/-D] directory -s configFile

Can you please suggest a method to do this?

jefftee
10th March 2016, 06:04
I don't see a way to override the format of the help function. I guess I would say that the help function is there to give you a convenient method of showing usage information. You don't have to use that of course, you can simply write your own usage information to stderr instead of using the built-in help/usage info.