QDebug Class | Qt Core (original) (raw)

Member Function Documentation

[since 6.5] template <typename Char, typename... Args> QDebug &QDebug::operator<<(const std::basic_string<Char, Args...> &s)

[since 6.5] template <typename Char, typename... Args> QDebug &QDebug::operator<<(std::basic_string_view<Char, Args...> s)

Writes the string or string-view s to the stream and returns a reference to the stream.

These operators only participate in overload resolution if Char is one of

This function was introduced in Qt 6.5.

[since 6.7] template <typename T, QDebug::if_qint128 = true> QDebug &QDebug::operator<<(T i)

[since 6.7] template <typename T, QDebug::if_quint128 = true> QDebug &QDebug::operator<<(T i)

Prints the textual representation of the 128-bit integer i.

Note: This operator is only available if Qt supports 128-bit integer types. If 128-bit integer types are available in your build, but the Qt libraries were compiled without, the operator will print a warning instead.

Note: Because the operator is a function template, no implicit conversions are performed on its argument. It must be exactly qint128/quint128.

This function was introduced in Qt 6.7.

See also QT_SUPPORTS_INT128.

[explicit] QDebug::QDebug(QIODevice *device)

Constructs a debug stream that writes to the given device.

[explicit] QDebug::QDebug(QString *string)

Constructs a debug stream that writes to the given string.

[explicit] QDebug::QDebug(QtMsgType t)

Constructs a debug stream that writes to the handler for the message type t.

QDebug::QDebug(const QDebug &o)

Constructs a copy of the other debug stream o.

[noexcept] QDebug::~QDebug()

Flushes any pending data to be written and destroys the debug stream.

bool QDebug::autoInsertSpaces() const

Returns true if this QDebug instance will automatically insert spaces between writes.

See also setAutoInsertSpaces() and QDebugStateSaver.

QDebug &QDebug::maybeQuote(char c = '"')

Writes a character c to the debug stream, depending on the current setting for automatic insertion of quotes, and returns a reference to the stream.

The default character is a double quote ".

See also quote() and noquote().

QDebug &QDebug::maybeSpace()

Writes a space character to the debug stream, depending on the current setting for automatic insertion of spaces, and returns a reference to the stream.

See also space() and nospace().

QDebug &QDebug::noquote()

Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream.

When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.

See also quote() and maybeQuote().

QDebug &QDebug::nospace()

Disables automatic insertion of spaces and returns a reference to the stream.

See also space() and maybeSpace().

QDebug &QDebug::quote()

Enables automatic insertion of quotation characters around QChar, QString and QByteArray contents and returns a reference to the stream.

Quoting is enabled by default.

See also noquote() and maybeQuote().

[noexcept, since 6.7] bool QDebug::quoteStrings() const

Returns true if this QDebug instance will quote strings streamed into it (which is the default).

This function was introduced in Qt 6.7.

See also QDebugStateSaver, quote(), noquote(), and setQuoteStrings().

QDebug &QDebug::resetFormat()

Resets the stream formatting options, bringing it back to its original constructed state.

See also space() and quote().

void QDebug::setAutoInsertSpaces(bool b)

Enables automatic insertion of spaces between writes if b is true; otherwise automatic insertion of spaces is disabled.

See also autoInsertSpaces() and QDebugStateSaver.

[since 6.7] void QDebug::setQuoteStrings(bool b)

Enables quoting of strings streamed into this QDebug instance if b is true; otherwise quoting is disabled.

The default is to quote strings.

This function was introduced in Qt 6.7.

See also QDebugStateSaver, quote(), noquote(), and quoteStrings().

void QDebug::setVerbosity(int verbosityLevel)

Sets the verbosity of the stream to verbosityLevel.

The allowed range is from 0 to 7. The default value is 2.

See also verbosity() and VerbosityLevel.

QDebug &QDebug::space()

Writes a space character to the debug stream and returns a reference to the stream.

The stream remembers that automatic insertion of spaces is enabled for future writes.

See also nospace() and maybeSpace().

[noexcept] void QDebug::swap(QDebug &other)

Swaps this debug stream instance with other. This operation is very fast and never fails.

[static, since 6.9] template QByteArray QDebug::toBytes(const T &object)

This is equivalent to passing object to QDebug::toString(object).toUtf8(), but more efficient.

This function was introduced in Qt 6.9.

See also toString().

[static, since 6.0] template QString QDebug::toString(const T &object)

Streams object into a QDebug instance that operates on a string, and then returns that string.

This function is useful for cases where you need the textual representation of an object for debugging, but cannot use operator<<. For example:

QTRY_VERIFY2(list.isEmpty(), [qPrintable](qstring.html#qPrintable)([QString](qstring.html)::fromLatin1(
    "Expected list to be empty, but it has the following items: %1")).arg([QDebug](qdebug.html#QDebug)::toString(list)));

The string is streamed using nospace().

This function was introduced in Qt 6.0.

See also toBytes().

int QDebug::verbosity() const

Returns the verbosity of the debug stream.

Streaming operators can check the value to decide whether verbose output is desired and print more information depending on the level. Higher values indicate that more information is desired.

The allowed range is from 0 to 7. The default value is 2.

See also setVerbosity() and VerbosityLevel.

QDebug &QDebug::verbosity(int verbosityLevel)

Sets the verbosity of the stream to verbosityLevel and returns a reference to the stream.

The allowed range is from 0 to 7. The default value is 2.

See also verbosity(), setVerbosity(), and VerbosityLevel.

[since 6.0] QDebug &QDebug::operator<<(QByteArrayView t)

Writes the data of the observed byte array, t, to the stream and returns a reference to the stream.

Normally, QDebug prints the data inside quotes and transforms control or non-US-ASCII characters to their C escape sequences (\xAB). This way, the output is always 7-bit clean and the string can be copied from the output and pasted back into C++ sources, if necessary.

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

See the QByteArray overload for examples.

This function was introduced in Qt 6.0.

QDebug &QDebug::operator<<(QChar t)

Writes the character, t, to the stream and returns a reference to the stream. Normally, QDebug prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the noquote() functionality, but note that some QDebug backends may not be 8-bit clean and may not be able to represent t.

QDebug &QDebug::operator<<(QLatin1StringView t)

Writes the string, t, to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

See the QString overload for examples.

QDebug &QDebug::operator<<(QStringView s)

Writes the string view, s, to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

See the QString overload for examples.

[since 6.0] QDebug &QDebug::operator<<(QUtf8StringView s)

Writes the string view, s, to the stream and returns a reference to the stream.

Normally, QDebug prints the data inside quotes and transforms control or non-US-ASCII characters to their C escape sequences (\xAB). This way, the output is always 7-bit clean and the string can be copied from the output and pasted back into C++ sources, if necessary.

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

This function was introduced in Qt 6.0.

QDebug &QDebug::operator<<(bool t)

Writes the boolean value, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(char t)

Writes the character, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(char16_t t)

Writes the UTF-16 character, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(char32_t t)

Writes the UTF-32 character, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(const QByteArray &t)

Writes the byte array, t, to the stream and returns a reference to the stream. Normally, QDebug prints the array inside quotes and transforms control or non-US-ASCII characters to their C escape sequences (\xAB). This way, the output is always 7-bit clean and the string can be copied from the output and pasted back into C++ sources, if necessary.

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

Output examples:

[QByteArray](qbytearray.html) ba;

ba = "a";
[qDebug](qtlogging.html#qDebugx)().noquote() << ba;    // prints: a
[qDebug](qtlogging.html#qDebugx)() << ba;              // prints: "a"

ba = "\"a\r\n\"";
[qDebug](qtlogging.html#qDebugx)() << ba;              // prints: "\"a\r\n\""

ba = "\033";                 // escape character
[qDebug](qtlogging.html#qDebugx)() << ba;              // prints: "\x1B"

ba = "\xC3\xA1";
[qDebug](qtlogging.html#qDebugx)() << ba;              // prints: "\xC3\xA1"

ba = [QByteArray](qbytearray.html)("a\0b", 3);
[qDebug](qtlogging.html#qDebugx)() << ba               // prints: "\a\x00""b"

Note how QDebug needed to close and reopen the string in the way C and C++ languages concatenate string literals so that the letter 'b' is not interpreted as part of the previous hexadecimal escape sequence.

QDebug &QDebug::operator<<(const QString &t)

Writes the string, t, to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).

To print non-printable characters without transformation, enable the noquote() functionality. Note that some QDebug backends might not be 8-bit clean.

Output examples:

[QString](qstring.html) s;

s = "a";
[qDebug](qtlogging.html#qDebugx)().noquote() << s;    // prints: a
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "a"

s = "\"a\r\n\"";
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "\"a\r\n\""

s = "\033";                 // escape character
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "\u001B"

s = "\u00AD";               // SOFT HYPHEN
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "\u00AD"

s = "\u00E1";               // LATIN SMALL LETTER A WITH ACUTE
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "á"

s = "a\u0301";              // "a" followed by COMBINING ACUTE ACCENT
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "á";

s = "\u0430\u0301";         // CYRILLIC SMALL LETTER A followed by COMBINING ACUTE ACCENT
[qDebug](qtlogging.html#qDebugx)() << s;              // prints: "а́"

QDebug &QDebug::operator<<(const char *t)

Writes the '\0'-terminated UTF-8 string, t, to the stream and returns a reference to the stream. The string is never quoted or escaped for the output. Note that QDebug buffers internally as UTF-16 and may need to transform to 8-bit using the locale's codec in order to use some backends, which may cause garbled output (mojibake). Restricting to US-ASCII strings is recommended.

[since 6.0] QDebug &QDebug::operator<<(const char16_t *t)

Writes the u'\0'-terminated UTF-16 string, t, to the stream and returns a reference to the stream. The string is never quoted or escaped for the output. Note that QDebug buffers internally as UTF-16 and may need to transform to 8-bit using the locale's codec in order to use some backends, which may cause garbled output (mojibake). Restricting to US-ASCII strings is recommended.

This function was introduced in Qt 6.0.

[since 6.7] template <typename T, QDebug::if_streamable = true> QDebug &QDebug::operator<<(const std::optional<T> &opt)

Writes the contents of opt (or nullopt if not set) to this stream. T needs to support streaming into QDebug.

This function was introduced in Qt 6.7.

[since 6.9] template <typename... Ts, QDebug::if_streamable<Ts...> = true> QDebug &QDebug::operator<<(const std::tuple<Ts...> &tuple)

Writes the contents of tuple to the stream. All Ts... need to support streaming into QDebug.

This function was introduced in Qt 6.9.

QDebug &QDebug::operator<<(const void *t)

Writes a pointer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(double t)

Writes the 64-bit floating point number, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(float t)

Writes the 32-bit floating point number, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(int t)

Writes the signed integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(long t)

Writes the signed long integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(qint64 t)

Writes the signed 64-bit integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(quint64 t)

Writes then unsigned 64-bit integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(short t)

Writes the signed short integer, t, to the stream and returns a reference to the stream.

[since 6.6] template <typename Rep, typename Period> QDebug &QDebug::operator<<(std::chrono::duration<Rep, Period> duration)

Prints the time duration duration to the stream and returns a reference to the stream. The printed string is the numeric representation of the period followed by the time unit, similar to what the C++ Standard Library would produce with std::ostream.

The unit is not localized.

This function was introduced in Qt 6.6.

[since 6.7] QDebug &QDebug::operator<<(std::nullopt_t)

Writes nullopt to the stream.

This function was introduced in Qt 6.7.

QDebug &QDebug::operator<<(unsigned int t)

Writes then unsigned integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(unsigned long t)

Writes then unsigned long integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator<<(unsigned short t)

Writes then unsigned short integer, t, to the stream and returns a reference to the stream.

QDebug &QDebug::operator=(const QDebug &other)

Assigns the other debug stream to this stream and returns a reference to this stream.

template QDebug operator<<(QDebug _debug_, const QContiguousCache<T> &cache)

Writes the contents of cache to debug. T needs to support streaming into QDebug.

template QDebug operator<<(QDebug _debug_, const QFlags<T> &flags)

Writes flags to debug.

template <typename Key, typename T> QDebug operator<<(QDebug _debug_, const QHash<Key, T> &hash)

Writes the contents of hash to debug. Both Key and T need to support streaming into QDebug.

template QDebug operator<<(QDebug _debug_, const QList<T> &list)

Writes the contents of list to debug. T needs to support streaming into QDebug.

template <typename Key, typename T> QDebug operator<<(QDebug _debug_, const QMap<Key, T> &map)

Writes the contents of map to debug. Both Key and T need to support streaming into QDebug.

template <typename Key, typename T> QDebug operator<<(QDebug _debug_, const QMultiHash<Key, T> &hash)

Writes the contents of hash to debug. Both Key and T need to support streaming into QDebug.

template <typename Key, typename T> QDebug operator<<(QDebug _debug_, const QMultiMap<Key, T> &map)

Writes the contents of map to debug. Both Key and T need to support streaming into QDebug.

template QDebug operator<<(QDebug _debug_, const QSet<T> &set)

Writes the contents of set to debug. T needs to support streaming into QDebug.

[since 6.3] template <typename T, qsizetype P> QDebug operator<<(QDebug _debug_, const QVarLengthArray<T, P> &array)

Writes the contents of array to debug. T needs to support streaming into QDebug.

This function was introduced in Qt 6.3.

[since 6.9] template <typename T, std::size_t N> QDebug operator<<(QDebug _debug_, const std::array<T, N> &array)

Writes the contents of array to debug. T needs to support streaming into QDebug.

This function was introduced in Qt 6.9.

template <typename T, typename Alloc> QDebug operator<<(QDebug _debug_, const std::list<T, Alloc> &vec)

Writes the contents of list vec to debug. T needs to support streaming into QDebug.

template <typename Key, typename T, typename Compare, typename Alloc> QDebug operator<<(QDebug _debug_, const std::map<Key, T, Compare, Alloc> &map)

Writes the contents of map to debug. Both Key and T need to support streaming into QDebug.

template <typename Key, typename T, typename Compare, typename Alloc> QDebug operator<<(QDebug _debug_, const std::multimap<Key, T, Compare, Alloc> &map)

Writes the contents of map to debug. Both Key and T need to support streaming into QDebug.

[since 6.9] template <typename Key, typename Compare, typename Alloc> QDebug operator<<(QDebug _debug_, const std::multiset<Key, Compare, Alloc> &multiset)

Writes the contents of multiset to debug. The Key type needs to support streaming into QDebug.

This function was introduced in Qt 6.9.

template <typename T1, typename T2> QDebug operator<<(QDebug _debug_, const std::pair<T1, T2> &pair)

Writes the contents of pair to debug. Both T1 and T2 need to support streaming into QDebug.

[since 6.9] template <typename Key, typename Compare, typename Alloc> QDebug operator<<(QDebug _debug_, const std::set<Key, Compare, Alloc> &set)

Writes the contents of set to debug. The Key type needs to support streaming into QDebug.

This function was introduced in Qt 6.9.

[since 6.9] template <typename Key, typename T, typename Hash, typename KeyEqual, typename Alloc> QDebug operator<<(QDebug _debug_, const std::unordered_map<Key, T, Hash, KeyEqual, Alloc> &map)

Writes the contents of map to debug. Both Key and T need to support streaming into QDebug.

This function was introduced in Qt 6.9.

[since 6.9] template <typename Key, typename Hash, typename KeyEqual, typename Alloc> QDebug operator<<(QDebug _debug_, const std::unordered_set<Key, Hash, KeyEqual, Alloc> &unordered_set)

Writes the contents of unordered_set to debug. The Key type needs to support streaming into QDebug.

This function was introduced in Qt 6.9.

template <typename T, typename Alloc> QDebug operator<<(QDebug _debug_, const std::vector<T, Alloc> &vec)

Writes the contents of vector vec to debug. T needs to support streaming into QDebug.

[since 6.9] template <typename T, QDebug::if_ordering_type = true> QDebug operator<<(QDebug debug, T t)

Prints the Qt or std ordering value t to the debug object.

Constraints

Participates in overload resolution only if T is one of <Qt/Std>::<weak/partial/strong>_ordering.

This function was introduced in Qt 6.9.