首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

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

2012-07-25 
[原创]QT中进行debug输出和使用cout cin等的问题本文参考了:http://doc.qt.nokia.com/stable/debug.html#w

[原创]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>头文件, 上述的方法都可以当输出流进行使用, 例如:

?

?

如果想要使用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();  }
?

热点排行