您的位置:首页 > 编程语言 > Qt开发

Window下Qt中用qDebug()输出调试信息到Console控制台的设置方法(转)

2014-07-11 23:09 465 查看


1. 使用警告和调试信息

qDubug():输出调试信息 

    Example: 

        qDebug( "my window handle = %x", myWidget->id() );

qWarning():输出警告信息 

    Example: 

        void f( int c )

        {

            if ( c > 200 )

                qWarning( "f: bad argument, c == %d", c );

        }

qFatal():输出致命错误信息 ,程序自动被迫中止

    Example: 

        int divide( int a, int b )

        {

            if ( b == 0 )                               // program error

                qFatal( "divide: cannot divide by zero" );

            return a/b;

        }

使用例子:

        #include <qapplication.h>

       #include <iostream.h>

        void myMessageOutput( int input );

        int main( int argc, char **argv )

        {

            QApplication a( argc, argv );

            int temp;

        

        while(1)

        {

            cout << "Please input 1 2 or 3 here and else for quit:"; 

            cin>>temp;

            myMessageOutput( temp )    ;

        }         

            return a.exec();

        }

       void myMessageOutput( int input )

        {

            switch ( input ) {

                case 1: 

                qDebug("The number you input is : %d ",input);

                    break;

                case 2:                   

                qWarning("The number you input is : %d ",input);

                    break;

                case 3:

                qWarning("The number you input is : %d ",input);    

                    break;                  

            default : 

                //qWarning("The number you input is : %d ,which is invalid here.",input);

                qFatal( "It will be quit." );

                //cout<<"It will be quit."<<endl ;

                //abort(); 

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  QT 调试信息