QT如何输出调试信息

复制自源于官方文档:

qCritical(const char *message, ...)

Calls the message handler with the critical message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. On QNX the message is sent to slogger2

It exits if the environment variable QT_FATAL_CRITICALS is not empty.

This function takes a format string and a list of arguments, similar to the C printf() function. The format should be a Latin-1 string.

Example:

 
  void load(const QString &fileName)
  {
      QFile file(fileName);
      if (!file.exists())
          qCritical("File '%s' does not exist!", qUtf8Printable(fileName));
  }
 

If you include <QtDebug>, a more convenient syntax is also available:

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

A space is inserted between the items, and a newline is appended at the end.

To suppress the output at runtime, install your own message handler with qInstallMessageHandler().

See also qDebug(), qInfo(), qWarning(), qFatal(), qInstallMessageHandler(), and Debugging Techniques.

qDebug(const char *message, ...)

Calls the message handler with the debug message message. 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. On QNX, the message is sent to slogger2. 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.

Example:

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

If you include <QtDebug>, a more convenient syntax is also available:

 
  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.

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

See also qInfo(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(), and Debugging Techniques.

qFatal(const char *message, ...)

Calls the message handler with the fatal message message. If no message handler has been installed, the message is printed to stderr. Under Windows, the message is sent to the debugger. On QNX the message is sent to slogger2

If you are using the default message handler this function will abort to create a core dump. On Windows, for debug builds, this function will report a _CRT_ERROR enabling you to connect a debugger to the application.

This function takes a format string and a list of arguments, similar to the C printf() function.

Example:

 
  int divide(int a, int b)
  {
      if (b == 0)                                // program error
          qFatal("divide: cannot divide by zero");
      return a / b;
  }
 

To suppress the output at runtime, install your own message handler with qInstallMessageHandler().

See also qDebug(), qInfo(), qWarning(), qCritical(), qInstallMessageHandler(), and Debugging Techniques.

qInfo(const char *message, ...)

Calls the message handler with the informational message message. 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. On QNX the message is sent to slogger2. This function does nothing if QT_NO_INFO_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.

Example:

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

If you include <QtDebug>, a more convenient syntax is also available:

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

With this syntax, the function returns a QDebug object that is configured to use the QtInfoMsg 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.

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

This function was introduced in Qt 5.5.

See also qDebug(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(), and Debugging Techniques.


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值