How can I see qDebug messages while debugging in QtCreator

前端 未结 7 1452
感动是毒
感动是毒 2021-02-04 06:38

I\'m making the transition from Eclipse CDT (with Qt integration plugin) to QtCreator 2.0 but there is still one thing that bother me with QtCreator :

When I debug in Qt

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 07:17

    While not a complete answer, you can install DebugView (If you're on an XP machine) to view the qDebug output while you try to figure this out.

    Another solution might be considered a hack, but works quite nicely, is to simply hijack debug messages yourself:

    #include 
    #include 
    #include 
    
    void msgHandler( QtMsgType type, const char* msg )
    {
        const char symbols[] = { 'I', 'E', '!', 'X' };
        QString output = QString("[%1] %2").arg( symbols[type] ).arg( msg );
        std::cerr << output.toStdString() << std::endl;
        if( type == QtFatalMsg ) abort();
    }
    
    int main(int argc, char *argv[])
    {
        qInstallMsgHandler( msgHandler );
        QCoreApplication a(argc, argv);
    
        qDebug() << "Hello world.";
        qWarning() << "Uh, oh...";
        qCritical() << "Oh, noes!";
        qFatal( "AAAAAAAAAH!" );
    
        return a.exec();
    }
    

    Which would output:

    [I] Hello world. 
    [E] Uh, oh... 
    [!] Oh, noes! 
    [X] AAAAAAAAAH!
    
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.
    

    This is actually a modification of some code that I use myself to send qDebug, qWarning, etc., to a log file.

提交回复
热议问题