Qdebug在qt调试中的应用

来源:互联网 发布:有关人工智能的文献 编辑:程序博客网 时间:2024/06/04 00:58
void qDebug ( const char * msg, ... )


Calls the message handler with the debug message msg. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the console, if it is a console application; otherwise, it is sent to the debugger. This function does nothing if QT_NO_DEBUG_OUTPUT was defined during compilation.


If you pass the function a format string and a list of arguments, it works in similar way to the C printf() function. The format should be a Latin-1 string.
如果向qDebug传递一个格式化的string和一个参数列表,它就跟C里面的printf()函数使用方法一样。

Example:


 qDebug("Items in list: %d", myList.size());

If you include <QtDebug>, a more convenient syntax is also available:
包含的头文件为<QtDebug>时,支持如下面所示的语法形式。

 qDebug() << "Brush:" << myQBrush << "Other value:" << i;


With this syntax, the function returns a QDebug object that is configured to use the QtDebugMsg message type. It automatically puts a single space between each item, and outputs a newline at the end. It supports many C++ and Qt types.

输出时,会自动的为每个变量中间添加一个空格,并且在句尾添加一个换行。

这种格式支持许多C++ 和Qt数据类型。

To suppress the output at run-time, install your own message handler with qInstallMsgHandler().

几个简单的例子:

 qDebug()<<"create file success";

  QString appDirPath = QApplication::applicationDirPath() + "/";

 qDebug() << "Current appDirPath:" << appDirPath;

0 0
原创粉丝点击