Home · All Classes · Main Classes · Deprecated

Debugging functions

Introduction

Qt provides the functions qDebug(), qWarning(), qCritical() and qFatal() for writing out warning and debug text. In MeeGo Touch the functions mDebug() and mWarning() have been added. This chapter provides an overview when to use which function.

Overview

Qt provides four functions for writing out warning and debug text:

In MeeGo Touch, use the functions mDebug() and mWarning() instead of qDebug() and qWarning(). The mDebug() and mWarning() functions have been extended by a module name which allows message filtering (see -output-prefix, -no-output-prefix).

Example:

mDebug("MComponentData") << "Testability plugin loaded successfully";
mWarning("MComponentData::setActiveWindow()") << "Attempting to activate unregistered window";

The module name is usually the name of the class with an optional method prefix.

Using debugging functions

Use the debugging functions according to the following guidelines:

mDebug()

Writes custom debug output. Add only mDebug() statements that are useful for future debugging. Remove all mDebug() statements that have only been added for fixing a current issue.

mWarning()

Reports warnings and recoverable errors. Only report a warning for unexpected events that are not already reported by the API. For example, do not report a warning if the parsing of some data failed and the failure is already reported by a return value. A warning is useful, for example, if a caching mechanism cannot be activated and this may considerably slow down the performance. In this case, the warning gives a hint about the root cause.

qCritical()

Writes critical error messages and reports system errors. Use qCritical() instead of mWarning(), if the functionality of the overall system is at risk.

qFatal()

Writes fatal error messages shortly before exiting. Use this function only if it is impossible to continue with the execution of further code. The qFatal() throws an exception.

Controlling debugging output

MeeGo Touch allows you to control which messages are shown and optionally stream the messages into a file.

-output-level

To specify which messages are shown, add -output-level {debug|warning|critical} as parameter when starting an application or set the environment variable M_OUTPUT_LEVEL.

If no output-level has been specified, on ARM environments critical is used as the default value. In other environments warning is used as default.

-output-file

By default, the output is written to stderr. To stream the output into a file, use -output-file {filename}.

-output-prefix, -no-output-prefix

You can specify a whitelist or blacklist for outputs with a specific prefix. To specify a whitelist, use -output-prefix {prefix}. To specify a blacklist, use -no-output-prefix {prefix}. The prefix is the given module name.


Copyright © 2010 Nokia Corporation
MeeGo Touch