Better debug output using QT_MESSAGE_PATTERN

Ferit Cubukcuoglu

If you are using Qt, you might have some qDebug or qWarning statements in your code. But did you know that you can greatly improve the output of those with the QT_MESSAGE_PATTERN environment variable? This blog post will give you some hints and examples of what you can do.

The default message pattern just prints the message (and the category if one was specified), but qDebug has the possibility to output more information. You can display cool things like the line of code, the function name or more by using some placeholders in the pattern.

QT_MESSAGE_PATTERN="%{message}"

Following placeholders are supported:

Placeholder Description
%{appname} QCoreApplication::applicationName()
%{category} Logging category
%{file} Path to source file
%{function} Function
%{line} Line in source file
%{message} The actual message
%{pid} QCoreApplication::applicationPid()
%{threadid} The system-wide ID of current thread (if it can be obtained)
%{qthreadptr} A pointer to the current QThread (result of QThread::currentThread())

View original post 270 mots de plus