PDA

View Full Version : Quoting problem with QProcess



the_bis
15th December 2006, 08:19
Hi,
I need help for using QProcess.
I have to run a cmd like this:


cmd -param1 -param2 value2 -param3 value3:title="My Title with spaces"

For param1 & param2 no problems; param3 dont'work.

My code is:



[...]
#include <qprocess.h>

int main (int argc, char **argv)
{

[...]

QApplication a (argc, argv);
QProcess *proc;

[...]

proc = new QProcess ();
proc->addArgument ("cmd");
proc->addArgument ("-param1");
proc->addArgument ("-param2");
proc->addArgument ("value2");
proc->addArgument ("-param3");
QString myCmd = "value3:title=\"My Title with spaces\"";
proc->addArgument (myCmd);

if (!proc->start())
{
// error handling
exit (-1);
}

return 0;

}


When I launch this program I have no error but the third parameter is not correct. This arrives quoted. I think I have to avoid quoting...
I'm using Linux with bash shell.

Thanks for any help,
the_bis

wysota
15th December 2006, 11:24
Well, if you quote it then it arrives quoted... When using bash (or other shell) you use quotes when you wish to inform the shell that a particular block of text is really a single element although it contains spaces or other special characters. QProcess doesn't use the shell, it invokes the command directly, so quoting is not needed. Try passing simply "value3:title=My Title with spaces" as the third argument.