Solved How to parse an command line argument string into a QStringList for QProcess ?
-
@lansing
In this case you would be far better generating the list of separate arguments whichQProcess::start()
wants, rather than making a string as you do now.QString executable = "x264.exe"; QStringList arguments = (QStringList() << "-i" << "xxxx" << "-o" << "test.mp4"); process->start(executable, arguments);
-
The command line will be entered by the users.
-
@lansing
Hi
And how does the user enter them ?I mean via some GUI or via actual command line parameters to your app`?
-
I have a gui with a textarea for the entry
-
@lansing
ok so user type one parameter pr line or does it come
like par1=1 par2=2 on same line ?So we need to find way to split it into elements and
often we can split on space or or new line. -
The commandline will be entered by the user in one line, without the executable at the start of the line.
-i xxxxx -o "D:\my test.mp4"
I tried splitting it by space but it failed when I included a file path.
-
@lansing
Why not just use multiple LineEdits?Input: [ ] output:[ ]
and then add -i and -o yourself when you build the QStringList
-
I think you're right, separating input/output file path from the argument string will resolve headache like this. Then the argument string can be easily splitted by space and put into a
QStringList
. -
There's also QCommandLineParser class that can take care of all the spacing, quoting and parsing problems for you.
-
@lansing said in How to parse an command line argument string into a QStringList for QProcess ?:
The commandline will be entered by the user in one line
Then instead of using the deprecated
QProcess::start()
which accepted a string you will want to use the new [static]QStringList QProcess::splitCommand(QStringView command), which effectively exposes the function to do the splitting into arguments that the oldstart()
used to offer. -
Thanks it worked like magic.
QString executable = "x264.exe"; QString arguments = " -i xxxxx -o test.mp4"; QStringList argumentsList = QProcess::splitCommand(arguments); process->start(executable, argumentsList );