Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to use quotation marks in QStrings?



  • Hi,

    I was wondering:
    When I use something like this, how do I have it get quotation marks in the output?

      qDebug() << "I want this to display in quotation marks:\n";
    

    Like, this doesn't work:

      qDebug() << ""I want this to display in quotation marks:\n"";
    

    Thanks in advance!



  • @bartvrossum

    Hi,

    escape it with \.

    qDebug() << "\"Foo\"";


  • Moderators

    " is a special character inside a string, so, like with \n you need to escape it with \:

    qDebug() << "\"I want this to display in quotation marks:\n\"";
    

    or with C++11 you can use it unescaped enclosed in R"( and )"

    qDebug() << R"("I want this to display in quotation marks:
    ")";
    

Log in to reply