Common Ways to Use qDebug in Qt
Common Ways to Use qDebug in Qt
Basic Output: Use the qDebug() function to directly output messages. For example:
You need to include the header file.
#include <QDebug>
qDebug() << "This is a debug message";
Connect Multiple Values Using Stream Operator («): You can use the stream operator « to connect multiple values and output them together to qDebug. For example:
int value = 123;
QString message = "Hello, Qt!";
qDebug() << "Value:" << value << "Message:" << message;
Specify Debug Message Type: You can use different overloaded functions of qDebug to specify different debug message types, such as qInfo, qWarning, and qCritical, which help differentiate messages of various levels. For example:
qInfo() << "This is an informational message";
qWarning() << "This is a warning message";
qCritical() << "This is a critical error message";