I have a Qt5/C++ program which receives a QString containing a program name and possibly parameters. I need to split this QString into multiple strings. For example, the strin
Extract parameters from string, included quoted regions, in Qt
When parsing any "escaped" or quoted string: splitArgs
(from KF5) was immensely useful.
The following source code manages "escaping" and more; from
one two a\ b "c d e"
it prints
one
two
a b
c d e
The core of the source code is just a splitArgs
call:
#include
#include
int main()
{
QString whole = "one two a\\ b \"c d e\"";
QTextStream(stdout) << whole << endl << "--------------------" << endl;
QStringList group = KShell::splitArgs("one two a\\ b \"c d e\"");
for (auto element: group) {
QTextStream(stdout) << element << endl;
}
}