逛奔的蜗牛

我不聪明,但我会很努力

   ::  :: 新随笔 ::  ::  :: 管理 ::


void testMessagePattern() {
    QString QT_MESSAGE_PATTERN=
            "[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}]"
            ": %{file}:%{line} - %{message}";
    qSetMessagePattern(QT_MESSAGE_PATTERN);

    qDebug() << "Hello Pattern";
    qDebug() << QString("黄彪").toUtf8().toHex();
}

[D]: /Users/Biao/Dropbox/workspace/Qt/Test/main.cpp:26 - Hello Pattern

[D]: /Users/Biao/Dropbox/workspace/Qt/Test/main.cpp:28 - "e9bb84e5bdaa"


void qSetMessagePattern(const QString & pattern)

Changes the output of the default message handler.

Allows to tweak the output of qDebug(), qWarning(), qCritical() and qFatal().

Following placeholders are supported:

PlaceholderDescription
%{appname} QCoreApplication::applicationName()
%{file} Path to source file
%{function} Function
%{line} Line in source file
%{message} The actual message
%{pid} QCoreApplication::applicationPid()
%{threadid} ID of current thread
%{type} "debug", "warning", "critical" or "fatal"

You can also use conditionals on the type of the message using %{if-debug}%{if-warning}%{if-critical} or %{if-fatal} followed by an %{endif}. What is inside the%{if-*} and %{endif} will only be printed if the type matches.

Example:

QT_MESSAGE_PATTERN="[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"

The default pattern is "%{message}".

The pattern can also be changed at runtime by setting the QT_MESSAGE_PATTERN environment variable; if both qSetMessagePattern() is called and QT_MESSAGE_PATTERN is set, the environment variable takes precedence.

qSetMessagePattern() has no effect if a custom message handler is installed.

This function was introduced in QtCore 5.0.

See also qInstallMessageHandler() and Debugging Techniques.


posted on 2013-09-02 17:48 逛奔的蜗牛 阅读(1153) 评论(0)  编辑 收藏 引用 所属分类: Qt

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理