How to print QString containing line breaks using qDebug

前端 未结 1 1308
感情败类
感情败类 2020-12-17 20:15

This code:

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

leads to this output:

\"test1\\ntest2\"


        
相关标签:
1条回答
  • 2020-12-17 20:27

    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;
    

    Warning:

    qDebug(), qInfo(), qWarning(), qCritical() and qFatal() are all provided for debugging purposes. They are not meant to display something to the user in production code.

    Please, don't use these methods unless you are printing/logging some debug statements.

    0 讨论(0)
提交回复
热议问题