Double quotes in QString
The standard way of displaying double quotes in a std::string is by doing string str("\""); . However I see this doesn't work with QStrings:
QString str("a\"bc\""); qDebug()<<str; qDebug()<<"a\"bc\"";
The first qDebug prints a\"bc\" , while the second works and prints a"bc" . Any ideas ?
it's not QString, it's qDebug() see https://bugreports.qt.io/browse/QTBUG-48517 for example with Mr. Knoll himself answering
@cpper Of course it works, this is how C++ does it and has nothing to do with Qt. What you're observing is expected, as
qDebug()will escape any non-alphanum characters (including non-printables).
the intention for this behavior was to make it easier to debug what's inside QStrings.
If you want to display the contents you need to do
qDebug() << QString(...).toUtf8().constData(), what's actually your second approach.
If you want to display the contents you need to do qDebug() << QString(...).toUtf8().constData()
Or what I usually suggest:
QTextStream out(stdout); out << str;
All clear now. Thanks guys :)
Yet another option, cause you can never have too much ;) :
qDebug().noquote() << str;