QDebug Class▲
-
Header: QDebug
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Inherits: QIODeviceBase
-
Group: QDebug is part of Implicitly Shared Classes
Detailed Description▲
QDebug is used whenever the developer needs to write out debugging or tracing information to a device, file, string or console.
Basic Use▲
In the common case, it is useful to call the qDebug() function to obtain a default QDebug object to use for writing debugging information.
qDebug() &
lt;&
lt; "Date:"
&
lt;&
lt; QDate::
currentDate();
qDebug() &
lt;&
lt; "Types:"
&
lt;&
lt; QString("String"
) &
lt;&
lt; QChar('x'
) &
lt;&
lt; QRect(0
, 10
, 50
, 40
);
qDebug() &
lt;&
lt; "Custom coordinate type:"
&
lt;&
lt; coordinate;
This constructs a QDebug object using the constructor that accepts a QtMsgType value of QtDebugMsg. Similarly, the qWarning(), qCritical() and qFatal() functions also return QDebug objects for the corresponding message types.
The class also provides several constructors for other situations, including a constructor that accepts a QFile or any other QIODevice subclass that is used to write debugging information to files and other devices. The constructor that accepts a QString is used to write to a string for display or serialization.