Results 1 to 6 of 6

Thread: Inserting Double quotes inside QString

  1. #1
    Join Date
    Apr 2017
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2017
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,686
    Thanks
    257
    Thanked 748 Times in 738 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Inserting Double quotes inside QString

    Probably because you are using /" and not \" in your command string.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Apr 2017
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Inserting Double quotes inside QString

    Sorry it was a typing error.
    Am using "adb shell \"echo path of register\""

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,686
    Thanks
    257
    Thanked 748 Times in 738 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Inserting Double quotes inside QString

    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\").
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 3
    Last Post: 24th April 2016, 06:27
  2. C++/Qt5 - Adding quotes " into a QString
    By jimbo in forum Qt Programming
    Replies: 11
    Last Post: 12th January 2016, 13:02
  3. Replies: 9
    Last Post: 12th December 2015, 21:46
  4. Replies: 7
    Last Post: 21st March 2014, 10:24
  5. Replies: 2
    Last Post: 5th December 2013, 06:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.