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
-
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 doqDebug() << QString(...).toUtf8().constData()
, what's actually your second approach. -
@raven-worx said in Double quotes in QString:
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;
-
Yet another option, cause you can never have too much ;) :
qDebug().noquote() << str;