How to print string literal and QString with qDebug?

B Faley picture B Faley · Aug 25, 2013 · Viewed 84.1k times · Source

Is there any easy way to get the following work? I mean is there any helper class in Qt which prepares the string for qDebug?

QString s = "value";
qDebug("abc" + s + "def");

Answer

Kurt Pattyn picture Kurt Pattyn · Aug 25, 2013

You can use the following:

qDebug().nospace() << "abc" << qPrintable(s) << "def";

The nospace() is to avoid printing out spaces after every argument (which is default for qDebug()).