QDebug Class▲
-
Header: QDebug
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Inherits: https://
-
Group: QDebug is part of https://
Detailed Description▲
https:// 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 https://() function to obtain a default https:// object to use for writing debugging information.
qDebug() << "Date:" << QDate::currentDate();
qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40);
qDebug() << "Custom coordinate type:" << coordinate;This constructs a https:// object using the constructor that accepts a https:// value of https://. Similarly, the https://(), https://() and https://() functions also return https:// objects for the corresponding message types.
The class also provides several constructors for other situations, including a constructor that accepts a https:// or any other https:// subclass that is used to write debugging information to files and other devices. The constructor that accepts a https:// is used to write to a string for display or serialization.
Formatting Options▲
https:// formats output so that it's easily readable. It automatically adds spaces between arguments, and adds quotes around https://, https://, https:// arguments.
You can tweak these options through the https://(), https://() and https://(), https://() methods. Furthermore, https:// can be piped into a https:// stream.
https:// limits changes to the formatting to the current scope. https://() resets the options to the default ones.
Writing Custom Types to a Stream▲
Many standard types can be written to https:// objects, and Qt provides support for most Qt value types. To add support for custom types, you need to implement a streaming operator, as in the following example:
QDebug operator<<(QDebug debug, const Coordinate &c)
{
QDebugStateSaver saver(debug);
debug.nospace() << '(' << c.x() << ", " << c.y() << ')';
return debug;
}This is described in the https:// and Creating Custom Qt Types documents.
Member Type Documentation▲
[since 5.13] enum QDebug::VerbosityLevel▲
This enum describes the range of verbosity levels.
|
Constant |
|
|---|---|
|
https://::MinimumVerbosity |
0 |
|
https://::DefaultVerbosity |
2 |
|
https://::MaximumVerbosity |
7 |
This enum was introduced or modified in Qt 5.13.
See Also▲
See also https://(), https://()
Member Function Documentation▲
[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.
QDebug::~QDebug()▲
Flushes any pending data to be written and destroys the debug stream.
[since 5.0] bool QDebug::autoInsertSpaces() const▲
Returns true if this https:// instance will automatically insert spaces between writes.
This function was introduced in Qt 5.0.
See Also▲
See also https://(), https://
[since 5.4] 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 ".
This function was introduced in Qt 5.4.
See Also▲
See also https://(), https://()
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▲
See also https://(), https://()
[since 5.4] QDebug &QDebug::noquote()▲
Disables automatic insertion of quotation characters around https://, https:// and https:// 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.
This function was introduced in Qt 5.4.
See Also▲
See also https://(), https://()
QDebug &QDebug::nospace()▲
Disables automatic insertion of spaces and returns a reference to the stream.
See Also▲
See also https://(), https://()
[since 5.4] QDebug &QDebug::quote()▲
Enables automatic insertion of quotation characters around https://, https:// and https:// contents and returns a reference to the stream.
Quoting is enabled by default.
This function was introduced in Qt 5.4.
See Also▲
See also https://(), https://()
[since 5.4] QDebug &QDebug::resetFormat()▲
Resets the stream formatting options, bringing it back to its original constructed state.
This function was introduced in Qt 5.4.
See Also▲
See also https://(), https://()
[since 5.0] void QDebug::setAutoInsertSpaces(bool b)▲
Enables automatic insertion of spaces between writes if b is true; otherwise automatic insertion of spaces is disabled.
This function was introduced in Qt 5.0.
See Also▲
See also https://(), https://
[since 5.6] 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.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://
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▲
See also https://(), https://()
[since 5.0] void QDebug::swap(QDebug &other)▲
Swaps this debug stream instance with other. This function is very fast and never fails.
This function was introduced in Qt 5.0.
[static, since 6.0] QString QDebug::toString(T &&object)▲
Streams object into a https:// 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::fromLatin1(
"Expected list to be empty, but it has the following items: %1")).arg(QDebug::toString(list)));The string is streamed using https://().
This function was introduced in Qt 6.0.
[since 5.13] 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.
This function was introduced in Qt 5.13.
See Also▲
See also https://(), https://(), https://
[since 5.6] 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.
This function was introduced in Qt 5.6.
See Also▲
See also https://(), https://
QDebug &QDebug::operator<<(QChar t)▲
Writes the character, t, to the stream and returns a reference to the stream. Normally, https:// 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 https://() functionality, but note that some https:// backends may not be 8-bit clean and may not be able to represent t.
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<<(short t)▲
Writes the signed short 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.
[since 5.5] QDebug &QDebug::operator<<(char16_t t)▲
Writes the UTF-16 character, t, to the stream and returns a reference to the stream.
This function was introduced in Qt 5.5.
[since 5.5] QDebug &QDebug::operator<<(char32_t t)▲
Writes the UTF-32 character, t, to the stream and returns a reference to the stream.
This function was introduced in Qt 5.5.
QDebug &QDebug::operator<<(int t)▲
Writes the signed integer, t, to the stream and returns a reference to the stream.
QDebug &QDebug::operator<<(unsigned int t)▲
Writes then unsigned 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<<(unsigned long t)▲
Writes then unsigned 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<<(float t)▲
Writes the 32-bit floating point number, 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<<(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 https:// 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 https:// 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.
QDebug &QDebug::operator<<(const QString &t)▲
Writes the string, t, to the stream and returns a reference to the stream. Normally, https:// prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the https://() functionality. Note that some https:// backends might not be 8-bit clean.
Output examples:
QString s;
s = "a";
qDebug().noquote() << s; // prints: a
qDebug() << s; // prints: "a"
s = "\"a\r\n\"";
qDebug() << s; // prints: "\"a\r\n\""
s = "\033"; // escape character
qDebug() << s; // prints: "\u001B"
s = "\u00AD"; // SOFT HYPHEN
qDebug() << s; // prints: "\u00AD"
s = "\u00E1"; // LATIN SMALL LETTER A WITH ACUTE
qDebug() << s; // prints: "á"
s = "a\u0301"; // "a" followed by COMBINING ACUTE ACCENT
qDebug() << s; // prints: "á";
s = "\u0430\u0301"; // CYRILLIC SMALL LETTER A followed by COMBINING ACUTE ACCENT
qDebug() << s; // prints: "а́"[since 5.10] QDebug &QDebug::operator<<(QStringView s)▲
Writes the string view, s, to the stream and returns a reference to the stream. Normally, https:// prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the https://() functionality. Note that some https:// backends might not be 8-bit clean.
See the https:// overload for examples.
This function was introduced in Qt 5.10.
[since 6.0] QDebug &QDebug::operator<<(QUtf8StringView s)▲
Writes the string view, s, to the stream and returns a reference to the stream.
Normally, https:// 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 https://() functionality. Note that some https:// backends might not be 8-bit clean.
This function was introduced in Qt 6.0.
QDebug &QDebug::operator<<(QLatin1String t)▲
Writes the string, t, to the stream and returns a reference to the stream. Normally, https:// prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the https://() functionality. Note that some https:// backends might not be 8-bit clean.
See the https:// overload for examples.
QDebug &QDebug::operator<<(const QByteArray &t)▲
Writes the byte array, t, to the stream and returns a reference to the stream. Normally, https:// 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 https://() functionality. Note that some https:// backends might not be 8-bit clean.
Output examples:
QByteArray ba;
ba = "a";
qDebug().noquote() << ba; // prints: a
qDebug() << ba; // prints: "a"
ba = "\"a\r\n\"";
qDebug() << ba; // prints: "\"a\r\n\""
ba = "\033"; // escape character
qDebug() << ba; // prints: "\x1B"
ba = "\xC3\xA1";
qDebug() << ba; // prints: "\xC3\xA1"
ba = QByteArray("a\0b", 3);
qDebug() << ba // prints: "\a\x00""b"Note how https:// 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.
[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, https:// 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 https://() functionality. Note that some https:// backends might not be 8-bit clean.
See the https:// overload for examples.
This function was introduced in Qt 6.0.
QDebug &QDebug::operator<<(const void *t)▲
Writes a pointer, 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.
Related Non-Members▲
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 https://.
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 https://.
QDebug operator<<(QDebug debug, const QPair<T1, T2> &pair)▲
Writes the contents of pair to debug. Both T1 and T2 need to support streaming into https://.
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 https://.
QDebug operator<<(QDebug debug, const QContiguousCache<T> &cache)▲
Writes the contents of cache to debug. T needs to support streaming into https://.
QDebug operator<<(QDebug debug, const QFlags<T> &flags)▲
Writes flags to debug.
QDebug operator<<(QDebug debug, const QList<T> &list)▲
Writes the contents of list to debug. T needs to support streaming into https://.
[since 6.3] QDebug operator<<(QDebug debug, const QVarLengthArray<T, P> &array = P)▲
Writes the contents of array to debug. T needs to support streaming into https://.
This function was introduced in Qt 6.3.
[since 5.7] QDebug operator<<(QDebug debug, const std::list<T, Alloc> &vec)▲
Writes the contents of list vec to debug. T needs to support streaming into https://.
This function was introduced in Qt 5.7.
[since 5.7] QDebug operator<<(QDebug debug, const std::vector<T, Alloc> &vec)▲
Writes the contents of vector vec to debug. T needs to support streaming into https://.
This function was introduced in Qt 5.7.
QDebug operator<<(QDebug debug, const QSet<T> &set)▲
Writes the contents of set to debug. T needs to support streaming into https://.
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 https://.
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 https://.
[since 5.7] 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 https://.
This function was introduced in Qt 5.7.
[since 5.7] 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 https://.
This function was introduced in Qt 5.7.


