您的位置:首页 > 编程语言 > Qt开发

QT如何输出调试信息

2017-05-29 00:27 393 查看
复制自源于官方文档:
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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: