Debugging a C++ application
The QDebug
class can be used to print the value of a variable to the application output window. QDebug
is similar to std::cout
in the standard library, but it has the benefit of being part of Qt, which means it supports Qt classes out of the box and can display its value without the need for conversion.
To enable debugging messages, we must include the QDebug
header as follows:
#include <QDebug>
Qt provides several global macros for generating different types of debug messages. They can be used for different purposes, mentioned as follows:
qDebug()
provides a custom debug message.qInfo()
provides informational messages.qWarning()
reports warnings and recoverable errors.qCritical()
provides critical error messages and reports system errors.qFatal()
provides fatal error messages before exiting.
You can see if your feature is working correctly by using qDebug()
. After you've finished looking for the error...