`

[原创]QT中进行debug输出和使用cout cin等的问题

阅读更多

本文参考了:http://doc.qt.nokia.com/stable/debug.html#warning-and-debugging-messages

http://socol.iteye.com/blog/719500

 

在qt中大家都知道不能像纯C++那样使用cout等进行debug, 因为输出的内容会保留到程序退出的时候才进行输出。

 

Warning and Debugging Messages

Qt includes four global functions for writing out warning and debug text. You can use them for the following purposes:

Qt中包含了四个全局方法, 用于输出警告和调试信息, 列举如下:

  • qDebug () is used for writing custom debug output.用于输出调试信息
  • qWarning () is used to report warnings and recoverable errors in your application.警告信息
  • qCritical () is used for writing critical error mesages and reporting system errors.严重错误信息
  • qFatal () is used for writing fatal error messages shortly before exiting.很严重的错误, 输出后退出程序

If you include the <QtDebug> header file, the qDebug() function can also be used as an output stream. For example:

如果你include了<QtDebug>头文件, 上述的方法都可以当输出流进行使用, 例如:

 qDebug() << "Widget" << widget << "at position" << widget->pos();

 

 

如果想要使用cout, 应使用QTextStream重载

#include <QApplication>  
#include <QTextStream>  
  
int main(int argc, char *argv[])  
{  
    QApplication app(argc, argv);  
  
    QTextStream out(stdout);  //重载
  
    out << "is QTextStream out " << endl;  
  
    return app.exec();  
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics