Paddre Paddre - 7 months ago 102
C++ Question

How to print QString containing line breaks using qDebug

This code:

QString output("test1\ntest2");
qDebug() << output;

leads to this output:


What I want is:


So how can I use qDebug() (and similar output functors) to print a QString containing line break characters in multiple lines?


qDebug() is meant for debugging purposes, so it escapes non-printable characters and adds quotes when printing QString, QByteArray, QChar arguments.

Try using qDebug().noquote() as this disables escaping non-printable characters, like this:

QString output("test1\ntest2");
qDebug().noquote() << output;