Problem using QProcess with arguments that have quotes & contain spaces [Win32/64]
-
bq. I’m not master with Qt, so please be patient with my newbie’ish helping…
I apologize if my reply sounded rude or something.
bq. but can you get arguments you are passing to octave out as seen by octave?
Are you talking about taking a look at the string I'm finally passing to the Octave executable? Yes, I already looked into this, but there's no way in Qt (that I know of, I'm a newbie too... :)) to see what the QProcess object is actually doing with the 2 args (QString - exec. path; QStringList - arguments). Do you know of a way to do this?
-
No problems, I just have too sharp tongue sometimes...
I don't know what this "octave" is and how it expects to get the parameters herself, so I'd suggest to make a simple test program which you can use to test how the arguments behaves. If it works as expected with this dummy program, it is octave that interprets the arguments wrong.
-
spaces are easily handled, I just tried this with a jpg file in "Program Files" directory of windows:
@
QString cmd("mspaint");
QStringList args;
args << "c:\Program Files\tanu.jpg";
pr->start(cmd, args);
@ -
Just tried with double quotes with the below snip, and even that works!
@
QString cmd("firefox");
QStringList args;
args << "http://www.google.co.in/search?q="qt+jambi"";
pr->start(cmd, args);
@In my firefox, I had google with qt jambi search done and URL in the browser reads:
http://www.google.co.in/search?q="qt+jambi" -
to your comment:
[ P.S. The ‘forward slash’es I put in several places have been removed in the preview. I don’t know if they will be missing from the final post. ]
You can actually preview and see how it looks in the final post ... or use @code here @ ... and everything will be preserved :)
-
sorry .. use the @ symbol before and after ur code
-
Offtopic, but... You can also edit your posts, instead of making double posts.
And about code tags and quote tags and others: there are buttons for them at panel at top of this textarea...
bq. Just tried with double quotes with the below snip, and even that works!
Naturally, as it takes a QStringList as argument, it can handle all escaping by itself. It would be different story if you'd need to use single string for arguments and program; then you'd need to do the escaping yourself, because the framework can't read your thoughts.
When thinking this, always using QStringList for arguments saves time and avoid idiomatic bugs... When you forget one or two quotes from somewhere.
-
Thanks Smar, new to the forum and didn't realize I could edit a post :)
-
@
QStringList qslArguments;qslArguments.append("127.0.0.1"); qslArguments.append(qsStrapId); qpProcess.start("BMI_REMOTE", qslArguments);
@
This just works fine. Don't bother about quotes etc. Qt will do it for you if I'm not mistaken, dependent on the OS you are running. Windows normally has a / as a argument separator, Linux uses a space. Qt will fix it for you. It is also possible to handle it yourself using the overloaded function of process::start (). Here you can give just 1 Qstring with the program name and all parameters added yourself. You can easily debug it yourself, but that would make it a bit less OS independent.
good luck!