QDebug Class
The QDebug class provides an output stream for debugging information. More…
| Header | #include <QDebug> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QDebug(QtMsgType type) | |
| QDebug(QString *string) | |
| QDebug(QIODevice *device) | |
| QDebug(const QDebug &) | |
| QDebug & | operator=(const QDebug &) |
| ~QDebug() | |
| QDebug & | space() |
| QDebug & | nospace() |
| bool | autoInsertSpaces() const |
| void | setAutoInsertSpaces(bool b) |
| QDebug & | maybeSpace() |
| QDebug & | quote() |
| QDebug & | noquote() |
| bool | quoteStrings() const |
| void | setQuoteStrings(bool b) |
| QDebug & | maybeQuote(char c = '"') |
| int | verbosity() const |
| void | setVerbosity(int verbosityLevel) |
| QDebug & | verbosity(int verbosityLevel) |
| QDebug & | resetFormat() |
| void | swap(QDebug &other) |
| QDebug & | operator<<(bool v) |
| QDebug & | operator<<(char v) |
| QDebug & | operator<<(signed char v) |
| QDebug & | operator<<(unsigned char v) |
| QDebug & | operator<<(short v) |
| QDebug & | operator<<(unsigned short v) |
| QDebug & | operator<<(int v) |
| QDebug & | operator<<(unsigned int v) |
| QDebug & | operator<<(long v) |
| QDebug & | operator<<(unsigned long v) |
| QDebug & | operator<<(long long v) |
| QDebug & | operator<<(unsigned long long v) |
| QDebug & | operator<<(float v) |
| QDebug & | operator<<(double v) |
| QDebug & | operator<<(const char *v) |
| QDebug & | operator<<(const std::string &v) |
| QDebug & | operator<<(const void *p) |
| QDebug & | operator<<(std::nullptr_t) |
| QDebug & | operator<<(QChar c) |
| QDebug & | operator<<(const QString &v) |
| QDebug & | operator<<(QLatin1StringView v) |
| QDebug & | operator<<(QStringView v) |
| QDebug & | operator<<(const QByteArray &v) |
| QDebug & | operator<<(const QObject *o) |
| QDebug & | operator<<(QTextStreamFunction f) |
| QDebug & | operator<<(const QTextStreamManipulator &m) |
Static Public Members
| QString | toString(const T &object) |
| QByteArray | toBytes(const T &object) |
Detailed Description
QDebug is used to write human-readable diagnostics. Obtain a stream from qDebug(), qInfo(), qWarning() or qCritical() and write values to it with <<. The message is emitted when the stream, and every copy of it, is destroyed, so a statement such as
qDebug() << "value:" << 42 << QString("text");
produces one message, value: 42 "text". Spaces are inserted between values unless disabled with nospace(), and strings are quoted unless disabled with noquote().
A message is written to stderr followed by a newline, in the format set with qSetMessagePattern(), unless a handler was installed with qInstallMessageHandler(). That handler then receives the message type (QtDebugMsg, QtInfoMsg, QtWarningMsg, QtCriticalMsg or QtFatalMsg), a QMessageLogContext and the text instead. A QtFatalMsg message aborts the process after it is handled.
The same functions also have printf-style forms, such as qDebug("count: %d", n), and qFatal() takes a format string. A QLoggingCategory selects which messages are written; see qCDebug().
See also QMessageLogger, QMessageLogContext, QDebugStateSaver and QLoggingCategory.
Differences from Qt
The QTextStream manipulators, such as Qt::hex, Qt::fixed and qSetFieldWidth(), apply to numbers only, not to strings. There is no << for QMetaEnum. The containers supported are QList, QSet, QMap, QMultiMap, QHash, QMultiHash, std::vector, std::list and std::pair; a QList is written without the QList prefix. QFlags values are written as hexadecimal bits, because Nt does not look up Q_FLAG names here. The verbosity is stored but the built-in operators ignore it.
Member Function Documentation
QDebug::QDebug(QtMsgType type)
Constructs a debug stream that emits a message of the given type when it is destroyed.
QDebug::QDebug(QString *string)
Constructs a debug stream that appends its text to string when it is destroyed, instead of emitting a message. A space written after the last value is kept.
QDebug::QDebug(QIODevice *device)
Constructs a debug stream that writes its text to device, as UTF-8, when it is destroyed, instead of emitting a message. A space written after the last value is kept.
QDebug::QDebug(const QDebug &)
Constructs a copy of another stream. The copies share one buffer, and the message is emitted when the last copy is destroyed.
QDebug::~QDebug()
Destroys the stream. If this is the last copy of the stream, the accumulated message is emitted, with a trailing space removed, and for QtFatalMsg the process is aborted. A stream for a QString or a QIODevice writes its text there instead.
bool QDebug::autoInsertSpaces() const
Returns true if spaces are inserted between values automatically.
See also setAutoInsertSpaces(), space() and nospace().
QDebug & QDebug::maybeQuote(char c = '"')
Writes the character c to the stream if quoting is enabled, and returns a reference to the stream.
See also quote() and noquote().
QDebug & QDebug::maybeSpace()
Writes a space character to the stream if spaces are enabled, and returns a reference to the stream.
See also space() and nospace().
QDebug & QDebug::noquote()
Disables quoting of strings and characters, and returns a reference to the stream. Strings are then written without escaping.
See also quote() and maybeQuote().
QDebug & QDebug::nospace()
Disables the automatic insertion of spaces between values, and returns a reference to the stream.
See also space() and maybeSpace().
QDebug & QDebug::operator<<(bool v)
Writes the boolean value v to the debug stream as true or false, and returns a reference to the stream.
QDebug & QDebug::operator<<(char v)
This is an overloaded function.
Writes the character v to the debug stream, in single quotes if quoting is enabled.
QDebug & QDebug::operator<<(signed char v)
This is an overloaded function.
Writes the signed character v to the debug stream as a number.
QDebug & QDebug::operator<<(unsigned char v)
This is an overloaded function.
Writes the unsigned character v to the debug stream as a number.
QDebug & QDebug::operator<<(short v)
This is an overloaded function.
Writes the short integer v to the debug stream.
QDebug & QDebug::operator<<(unsigned short v)
This is an overloaded function.
Writes the unsigned short integer v to the debug stream.
QDebug & QDebug::operator<<(int v)
This is an overloaded function.
Writes the integer v to the debug stream.
QDebug & QDebug::operator<<(unsigned int v)
This is an overloaded function.
Writes the unsigned integer v to the debug stream.
QDebug & QDebug::operator<<(long v)
This is an overloaded function.
Writes the long integer v to the debug stream.
QDebug & QDebug::operator<<(unsigned long v)
This is an overloaded function.
Writes the unsigned long integer v to the debug stream.
QDebug & QDebug::operator<<(long long v)
This is an overloaded function.
Writes the long long integer v to the debug stream.
QDebug & QDebug::operator<<(unsigned long long v)
This is an overloaded function.
Writes the unsigned long long integer v to the debug stream.
QDebug & QDebug::operator<<(float v)
This is an overloaded function.
Writes the float v to the debug stream, using the shortest representation that reads back unchanged.
QDebug & QDebug::operator<<(double v)
This is an overloaded function.
Writes the double v to the debug stream, using the shortest representation that reads back unchanged.
QDebug & QDebug::operator<<(const char *v)
This is an overloaded function.
Writes the zero-terminated string v to the debug stream, without quotes or escaping. A null pointer is written as (null).
QDebug & QDebug::operator<<(const std::string &v)
This is an overloaded function.
Writes the string v to the debug stream, without quotes or escaping.
QDebug & QDebug::operator<<(const void *p)
This is an overloaded function.
Writes the pointer p to the debug stream as a hexadecimal address.
QDebug & QDebug::operator<<(std::nullptr_t)
This is an overloaded function.
Writes (nullptr) to the debug stream.
QDebug & QDebug::operator<<(QChar c)
This is an overloaded function.
Writes the character c to the debug stream as a one-character string.
QDebug & QDebug::operator<<(const QString &v)
This is an overloaded function.
Writes the string v to the debug stream, in double quotes and with special characters escaped if quoting is enabled.
See also quote() and noquote().
QDebug & QDebug::operator<<(QLatin1StringView v)
This is an overloaded function.
Writes the Latin-1 string v to the debug stream, as for a QString.
QDebug & QDebug::operator<<(QStringView v)
Writes the string view v to the debug stream, quoted and escaped like a QString, and returns a reference to the stream.
This function was introduced in 5.10.
QDebug & QDebug::operator<<(const QByteArray &v)
This is an overloaded function.
Writes the byte array v to the debug stream, in double quotes and with special characters escaped if quoting is enabled.
QDebug & QDebug::operator<<(const QObject *o)
This is an overloaded function.
Writes the object o to the debug stream as its address and, if set, its object name, for example QObject(0x1234, name = "x"). A null pointer is written as QObject(0x0).
QDebug & QDebug::operator<<(QTextStreamFunction f)
Applies the QTextStream manipulator f, such as Qt::hex, Qt::showbase, Qt::fixed or Qt::endl, and returns a reference to the stream. The settings change how later numbers are written:
qDebug() << Qt::hex << Qt::showbase << 255 << Qt::dec << 255; // 0xff 255
This function was introduced in 5.4.
QDebug & QDebug::operator<<(const QTextStreamManipulator &m)
Applies the manipulator m, made by qSetFieldWidth(), qSetPadChar() or qSetRealNumberPrecision(), and returns a reference to the stream.
This function was introduced in 5.4.
QDebug & QDebug::operator=(const QDebug &)
Assigns another stream to this stream and returns a reference to this stream. The two streams then share one buffer.
QDebug & QDebug::quote()
Enables quoting of strings and characters, and returns a reference to the stream. This is the default.
See also noquote() and maybeQuote().
bool QDebug::quoteStrings() const
Returns true if strings, characters and byte arrays are written in quotes; otherwise returns false.
This function was introduced in 6.10.
See also setQuoteStrings(), quote() and noquote().
QDebug & QDebug::resetFormat()
Restores the default formatting: automatic spaces, quoting and verbosity 2. Returns a reference to the stream.
This function was introduced in 5.4.
See also space(), quote() and setVerbosity().
void QDebug::setAutoInsertSpaces(bool b)
Sets whether spaces are inserted between values automatically to b.
See also autoInsertSpaces(), space() and nospace().
void QDebug::setQuoteStrings(bool b)
Turns the quoting of strings, characters and byte arrays on if b is true and off otherwise.
This function was introduced in 6.10.
See also quoteStrings(), quote() and noquote().
void QDebug::setVerbosity(int verbosityLevel)
Sets the verbosity of the stream to verbosityLevel, which is clamped to the range 0 to 7. Streaming operators may use it to decide how much detail to write.
This function was introduced in 5.6.
See also verbosity().
QDebug & QDebug::space()
Writes a space character after each value written to the stream, and returns a reference to the stream. This is the default.
See also nospace() and maybeSpace().
void QDebug::swap(QDebug &other)
Swaps this stream with other.
This function was introduced in 5.0.
template <typename T> QByteArray QDebug::toBytes(const T &object)
Returns object written to a debug stream, as UTF-8 encoded bytes.
This function was introduced in 6.9.
See also toString().
template <typename T> QString QDebug::toString(const T &object)
Returns object written to a debug stream, as a string. The stream does not insert spaces, so the result is what qDebug().nospace() would print.
This function was introduced in 6.0.
See also toBytes().
int QDebug::verbosity() const
Returns the verbosity of the stream, from 0 (least verbose) to 7 (most verbose). The default is 2.
This function was introduced in 5.6.
See also setVerbosity().
QDebug & QDebug::verbosity(int verbosityLevel)
This is an overloaded function.
Sets the verbosity of the stream to verbosityLevel and returns a reference to the stream.
This function was introduced in 5.13.