c++qtqstringqdebug

How to print string literal and QString with qDebug?


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");

Solution

  • No really easy way I am aware of. You can do:

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

    or

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