Inserting Double quotes inside QString
Hi All,
I am new to QT and am trying to insert double quotes inside QString, but am not able to do so. Below is the sample code am using.
QString var;
var = "adb shell \"echo some paths here\"";
when I print "var" am getting
"adb shell \"echo some paths here\"" (it is displaying including the escape character '\')
Anybody please help me, how to get
"adb shell "echo some paths here"".
Thank you.
Re: Inserting Double quotes inside QString
Looks like you are using qDebug() to print the var. qDebug() works that way.
use std::cout, it does what you want.
Re: Inserting Double quotes inside QString
Thank you Santosh.
you are right, after I displayed using std:cout am not seeing '\'.
Now am having a different issue.
Basically am trying to execute some "adb" commands from QT to control my android device.
Below is the sample code:
QProcess process;
QString adbCommand, status;
adbCommand = "adb shell /"echo > some register path/"";
qDebug() << "Command:" << adbCommand;
process.start(adbCommand);
process.waitForFinished(-1);
if(process.exitCode())
{
return("Error");
}
else
return (process.readAll());
when I execute the above code, am observing "Error (exitCode error and its value is 1)".
But if I execute the above adb command from command prompt everything works fine. Anybody please help me.
Initially I thought am not issuing the correct command from process.start(), but it seems that's not the issue.
Now am suspecting something is going wrong in process.start().
Anybody please help me.
Thank you.
Re: Inserting Double quotes inside QString
Probably because you are using /" and not \" in your command string.
Re: Inserting Double quotes inside QString
Sorry it was a typing error.
Am using "adb shell \"echo path of register\""
Re: Inserting Double quotes inside QString
Does the path string have spaces in it? If so, you'll also need to quote the path string. Alternatively, use the other form of QProcess::start() which takes a QString (the command, in your case adb), and a QStringList of arguments (shell, echo \"path\").