PDA

View Full Version : Inserting Double quotes inside QString



chandrashekar
17th April 2017, 06:50
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.

Santosh Reddy
17th April 2017, 14:02
Looks like you are using qDebug() to print the var. qDebug() works that way.

use std::cout, it does what you want.

chandrashekar
18th April 2017, 08:02
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.

d_stranz
19th April 2017, 00:51
Probably because you are using /" and not \" in your command string.

chandrashekar
19th April 2017, 05:45
Sorry it was a typing error.
Am using "adb shell \"echo path of register\""

d_stranz
20th April 2017, 21:45
path of register

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\").