Empty values of command line options
Solved
General and Desktop
-
The value of
databasePathOption
command line option in the code below is always empty:int main(int argc, char* argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QCoreApplication::setApplicationVersion("1.0"); QCoreApplication::setApplicationName("MyApp"); QCommandLineParser parser; parser.setApplicationDescription("My App"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption databasePathOption(QStringList() << "x" << "db123", QCoreApplication::translate("main", "Program database file path.")); parser.addOption(databasePathOption); parser.process(app); QString val = parser.value(databasePathOption); qDebug() << "db=" << val; ... }
I start the program with the following arguments:
--db123 "asdf"
but it prints an empty string.
What did I do wrong?
-
Hi,
From the documentation, you are missing the valueName parameter.