Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Double quotes in QString
cpper last edited by cpper
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 ?
VRonin last edited by
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;
cpper last edited by
All clear now. Thanks guys :)
Yet another option, cause you can never have too much ;) :
qDebug().noquote() << str;