This is because the &
(And commercial - ampersand) is used by the system to separate two commands on the same line, is a "special" character, just like pipe (|
) and the paranteses ((
and )
), and all can be escaped with ^
However if you are using Qt, it already has functions ready for this, which avoids you having to go through this trouble of escaping the characters, for example:
Using Qprocess with Qstringlist you can pass the arguments and the "Qt" itself will escape them to you:
retorno = "http://localhost:5000/robo/?Nome="+nome+"&Capital="+capital;
QProcess process;
process.start("start", QStringList() << retorno);
What should probably already solve, however it is interesting to note that Qt itself has a class called QDesktopServices
Which already aims to interact with operating system functions, ie if you port your program to Linux or OSX will not need to change anything in this part (will depend on what else you did), example with openUrl
(QUrl
it is necessary):
retorno = "http://localhost:5000/robo/?Nome="+nome+"&Capital="+capital;
QDesktopServices::openUrl(QUrl(retorno));
Okay, so it will fetch the program from the system that is associated with the URL protocol, in the case HTTP will probably open the default browser and also will not need "escapes" (like the ^
).
I can’t see a problem, it could be something where you’re using the variable. A [mcve] would be useful.
– Maniero
The return is sent to the system as follows system(return.toStdString(). c_str());
– Rodrigo Passerino
Isn’t it interaction problem with the console? I probably wouldn’t even do that
– Maniero
regardless of the &problem, it would probably be better in your case to use Qt’s own resources (or even OS natives) to start a process, rather than "start".
– Bacco