转载:QT中进行debug输出和使用cout cin等的问题

在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重载

Cpp代码 

 

  1. #include <QApplication>    
  2. #include <QTextStream>    
  3.     
  4. int main(int argc, char *argv[])    
  5. {    
  6.     QApplication app(argc, argv);    
  7.     
  8.     QTextStream out(stdout);  //重载  
  9.     
  10.     out << "is QTextStream out " << endl;    
  11.     
  12.     return app.exec();    
  13. }  

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值