How to print to console when using Qt

How to print to console when using Qt

Asked on December 14, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    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!”;

    Answered on December 14, 2018.
    Add Comment

    The simplest method:

    #include <QTextStream>
     
    QTextStream out(stdout);
    foreach(QString x, strings)
     out << x << endl;
    
    Answered on December 14, 2018.
    Add Comment

    Add the project file:

    CONFIG += console

    Answered on December 14, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.