How to send QString to debug output?

I cannot print QString in Qt using QDebug.

Below are some attempts (no one is working):

QDebug(letters.toStdString()); QDebug(letters.toLatin1()); QDebug() << letters.toUtf8(); QDebug() << letters.toWCharArray(); QDebug() << letters.toStdString(); QDebug() << letters; 

I turned on:

 #include <QtDebug> #include <QDebug> 

I am using Qt 5.2. I also added CONFIG += console to the project file

My mistake: "There is no suitable function to call QDebug :: QDebug ()"

I also got "QDebug (QByteArray) ambiguously" for QDebug(letters.toLatin1());

+6
source share
1 answer

The correct way to do this is:

 #include <QDebug> // snip... QString letters; qDebug() << letters; 

Be careful using qDebug() , starting with a qDebug() letter, as this is not the same as the QDebug class.

See http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qDebug . This is a convenience function that returns an already configured QDebug object.

+12
source

All Articles