QMessageLogger Class

The QMessageLogger class generates log messages. More...

Header: #include <QMessageLogger>
qmake: QT += core
Since: Qt 5.0

This class was introduced in Qt 5.0.

Public Types

Detailed Description

QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses it through qDebug(), qInfo(), qWarning(), qCritical, or qFatal() functions, which are actually macros: For example qDebug() expands to QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug() for debug builds, and QMessageLogger(0, 0, 0).debug() for release builds.

One example of direct use is to forward errors that stem from a scripting language, e.g. QML:

     void statusChanged(QDeclarativeComponent::Status status) {
         if (status == QDeclarativeComponent::Error) {
             foreach (const QDeclarativeError &error, component->errors()) {
                 const QByteArray file = error.url().toEncoded();
                 QMessageLogger(file.constData(), error.line(), 0).debug() << error.description();
             }
         }
     }

See also QMessageLogContext, qDebug(), qInfo(), qWarning(), qCritical(), and qFatal().

Member Type Documentation

typedef QMessageLogger::CategoryFunction

This is a typedef for a pointer to a function with the following signature:

     const QLoggingCategory &category();

A function which this signature is generated by Q_DECLARE_LOGGING_CATEGORY, Q_LOGGING_CATEGORY.

This typedef was introduced in Qt 5.3.