diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2012-01-17 16:20:45 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-01 02:16:32 +0100 |
commit | d394ca7f27197cfbfc28eb9a08eb0db261dd9d3d (patch) | |
tree | e75e133531101682473f91f5feca6c88c3e38c6c /doc/src/snippets/code | |
parent | ea783ff51f25af89b7219154d7be5de1fd138664 (diff) |
QtDebug: Include file, line, function information
Record the file, line, and function where a qDebug, qWarning, qCritical
or qFatal call happens, and make this information available in a custom
message handler.
The patch uses the C preprocessor to replace qDebug, qWarning, ... with
a line that also records the current file, line, and function. Custom
message handlers can access this information via a new QMessageLogContext
argument.
Change-Id: I0a9b89c1d137e41775932d3b1a35da4ebf12d18d
Reviewed-by: David Faure <faure@kde.org>
Diffstat (limited to 'doc/src/snippets/code')
-rw-r--r-- | doc/src/snippets/code/src_corelib_global_qglobal.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/doc/src/snippets/code/src_corelib_global_qglobal.cpp b/doc/src/snippets/code/src_corelib_global_qglobal.cpp index a45a136255..21bea7aef8 100644 --- a/doc/src/snippets/code/src_corelib_global_qglobal.cpp +++ b/doc/src/snippets/code/src_corelib_global_qglobal.cpp @@ -246,27 +246,27 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2) #include <stdio.h> #include <stdlib.h> -void myMessageOutput(QtMsgType type, const char *msg) +void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const char *msg) { switch (type) { case QtDebugMsg: - fprintf(stderr, "Debug: %s\n", msg); + fprintf(stderr, "Debug: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); break; case QtWarningMsg: - fprintf(stderr, "Warning: %s\n", msg); + fprintf(stderr, "Warning: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); break; case QtCriticalMsg: - fprintf(stderr, "Critical: %s\n", msg); + fprintf(stderr, "Critical: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); break; case QtFatalMsg: - fprintf(stderr, "Fatal: %s\n", msg); + fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", msg, context.file, context.line, context.function); abort(); } } int main(int argc, char **argv) { - qInstallMsgHandler(myMessageOutput); + qInstallMessageHandler(myMessageOutput); QApplication app(argc, argv); ... return app.exec(); @@ -532,6 +532,11 @@ class MyClass : public QObject CApaApplication *myApplicationFactory(); //! [47] + +//! [49] +void myMessageHandler(QtMsgType, const QMessageLogContext &, const char *); +//! [49] + //! [qlikely] // the condition inside the "if" will be successful most of the times for (int i = 1; i <= 365; i++) { |