How to print to console when using Qt
How to print to console when using Qt
Easy to print the stderr, the following streams are original for debugging:
//qInfo is qt5.5+ only. qInfo() << "C++ Style Info Message"; qInfo( "C Style Info Message" ); qDebug() << "C++ Style Debug Message"; qDebug( "C Style Debug Message" ); qWarning() << "C++ Style Warning Message"; qWarning( "C Style Warning Message" ); qCritical() << "C++ Style Critical Error Message"; qCritical( "C Style Critical Error Message" ); // qFatal does not have a C++ style method. qFatal( "C Style Fatal Error Message" );
The comments is to bear in mind qDebug messages are removed if QT_NO_DEBUG_OUTPUT is define
QTextStream& qStdOut() { static QTextStream ts( stdout ); return ts; }
The follow as
qStdOut() << “std out!”;
The simplest method:
#include <QTextStream> QTextStream out(stdout); foreach(QString x, strings) out << x << endl;