How to insert a double quotes in a QString?



  • Re: How to insert double quotes in the contents of a QString?
    The answer in the above thread is not understandable in C++ syntax. please help.
    My case is simple, I want Qt to avoid putting escape sequence in QString object. see this code.

    const char *s="dir=\"c:/Program Files\"";
    QString qs="dir=\"c:/Program Files\"";
    qDebug()<<s; // shows  dir="c:/Program Files"
    qDebug()<<qs;// shows  dir=\"c:/Program Files\"
    

    why qs added a back slash(or the escape sequence) ?


  • Qt Champions 2017

    @veenusav said in How to insert a double quotes in a QString?:

    why qs added a back slash(or the escape sequence) ?

    It doesn't. Just look at qs in a debugger. For some reason, qDebug() escapes inline quotes (that may be intentional, haven't investigated).



  • QString is fine, it's just qDebug that forces the print of escape chars. Use qDebug().noquote() << qs;



  • wonderful. You guys almost answered within seconds!. thank you. so qDebug() made me confused. so I will continue work peacefully. good day to you.


  • Qt Champions 2017

    @aha_1980 said in How to insert a double quotes in a QString?:

    For some reason, qDebug() escapes inline quotes (that may be intentional, haven't investigated).

    It's intentional, yes. There was a discussion about it, I think on the mailing list, about a year ago or so, I can't seem to dig it up though. But as far as I remember Thiago was adamant this is intended and correct behavior.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.