QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | Related Functions | List of all members
QDebug Class Reference

The QDebug class provides an output stream for debugging information. More...

#include <qdebug.h>

Inheritance diagram for QDebug:
Inheritance graph
[legend]
Collaboration diagram for QDebug:
Collaboration graph
[legend]

Public Types

enum  VerbosityLevel { MinimumVerbosity = 0 , DefaultVerbosity = 2 , MaximumVerbosity = 7 }
 
- Public Types inherited from QIODeviceBase
enum  OpenModeFlag {
  NotOpen = 0x0000 , ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = ReadOnly | WriteOnly ,
  Append = 0x0004 , Truncate = 0x0008 , Text = 0x0010 , Unbuffered = 0x0020 ,
  NewOnly = 0x0040 , ExistingOnly = 0x0080
}
 

Public Member Functions

 QDebug (QIODevice *device)
 
 QDebug (QString *string)
 
 QDebug (QtMsgType t)
 
 QDebug (const QDebug &o)
 
 QDebug (QDebug &&other) noexcept
 
QDebugoperator= (const QDebug &other)
 
 ~QDebug ()
 
void swap (QDebug &other) noexcept
 
QDebugresetFormat ()
 
QDebugspace ()
 
QDebugnospace ()
 
QDebugmaybeSpace ()
 
QDebugverbosity (int verbosityLevel)
 
int verbosity () const
 
void setVerbosity (int verbosityLevel)
 
bool autoInsertSpaces () const
 
void setAutoInsertSpaces (bool b)
 
QDebugquote ()
 
QDebugnoquote ()
 
QDebugmaybeQuote (char c='"')
 
QDebugoperator<< (QChar t)
 
QDebugoperator<< (bool t)
 
QDebugoperator<< (char t)
 
QDebugoperator<< (signed short t)
 
QDebugoperator<< (unsigned short t)
 
QDebugoperator<< (char16_t t)
 
QDebugoperator<< (char32_t t)
 
QDebugoperator<< (signed int t)
 
QDebugoperator<< (unsigned int t)
 
QDebugoperator<< (signed long t)
 
QDebugoperator<< (unsigned long t)
 
QDebugoperator<< (qint64 t)
 
QDebugoperator<< (quint64 t)
 
QDebugoperator<< (float t)
 
QDebugoperator<< (double t)
 
QDebugoperator<< (const char *t)
 
QDebugoperator<< (const char16_t *t)
 
QDebugoperator<< (const QString &t)
 
QDebugoperator<< (QStringView s)
 
QDebugoperator<< (QUtf8StringView s)
 
QDebugoperator<< (QLatin1String t)
 
QDebugoperator<< (const QByteArray &t)
 
QDebugoperator<< (QByteArrayView t)
 
QDebugoperator<< (const void *t)
 
QDebugoperator<< (std::nullptr_t)
 
QDebugoperator<< (QTextStreamFunction f)
 
QDebugoperator<< (QTextStreamManipulator m)
 

Static Public Member Functions

template<typename T >
static QString toString (T &&object)
 

Friends

class QMessageLogger
 
class QDebugStateSaver
 
class QDebugStateSaverPrivate
 

Related Functions

(Note that these are not member functions.)

template< class T > QDebug operator<< (QDebug debug, const QList< T > &list)
 
template< class T, qsizetype P > QDebug operator<< (QDebug debug, const QVarLengthArray< T, P > &array)
 
template< typename T, typename Alloc > QDebug operator<< (QDebug debug, const std::list< T, Alloc > &vec)
 
template< typename T, typename Alloc > QDebug operator<< (QDebug debug, const std::vector< T, Alloc > &vec)
 
template< typename T > QDebug operator<< (QDebug debug, const QSet< T > &set)
 
template< class Key, class T > QDebug operator<< (QDebug debug, const QMap< Key, T > &map)
 
template< class Key, class T > QDebug operator<< (QDebug debug, const QMultiMap< Key, T > &map)
 
template< typename Key, typename T, typename Compare, typename Alloc > QDebug operator<< (QDebug debug, const std::map< Key, T, Compare, Alloc > &map)
 
template< typename Key, typename T, typename Compare, typename Alloc > QDebug operator<< (QDebug debug, const std::multimap< Key, T, Compare, Alloc > &map)
 
template< class Key, class T > QDebug operator<< (QDebug debug, const QHash< Key, T > &hash)
 
template< class Key, class T > QDebug operator<< (QDebug debug, const QMultiHash< Key, T > &hash)
 
template< class T1, class T2 > QDebug operator<< (QDebug debug, const QPair< T1, T2 > &pair)
 
template< class T1, class T2 > QDebug operator<< (QDebug debug, const std::pair< T1, T2 > &pair)
 
template< typename T > QDebug operator<< (QDebug debug, const QContiguousCache< T > &cache)
 
template< typename T > QDebug operator<< (QDebug debug, const QFlags< T > &flags)
 

Additional Inherited Members

- Protected Member Functions inherited from QIODeviceBase
 ~QIODeviceBase ()=default
 

Detailed Description

The QDebug class provides an output stream for debugging information.

\inmodule QtCore

QDebug is used whenever the developer needs to write out debugging or tracing information to a device, file, string or console.

Definition at line 64 of file qdebug.h.

Member Enumeration Documentation

◆ VerbosityLevel

Since
5.13

This enum describes the range of verbosity levels.

\value MinimumVerbosity \value DefaultVerbosity \value MaximumVerbosity

See also
verbosity(), setVerbosity()
Enumerator
MinimumVerbosity 
DefaultVerbosity 
MaximumVerbosity 

Definition at line 118 of file qdebug.h.

Constructor & Destructor Documentation

◆ QDebug() [1/5]

QDebug::QDebug ( QIODevice device)
inlineexplicit

Constructs a debug stream that writes to the given device.

Definition at line 100 of file qdebug.h.

◆ QDebug() [2/5]

QDebug::QDebug ( QString string)
inlineexplicit

Constructs a debug stream that writes to the given string.

Definition at line 101 of file qdebug.h.

◆ QDebug() [3/5]

QDebug::QDebug ( QtMsgType  t)
inlineexplicit

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

Definition at line 102 of file qdebug.h.

◆ QDebug() [4/5]

QDebug::QDebug ( const QDebug o)
inline

Constructs a copy of the other debug stream o.

Definition at line 103 of file qdebug.h.

◆ QDebug() [5/5]

QDebug::QDebug ( QDebug &&  other)
inlinenoexcept

Definition at line 104 of file qdebug.h.

Here is the call graph for this function:

◆ ~QDebug()

QDebug::~QDebug ( )

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

Definition at line 196 of file qdebug.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ autoInsertSpaces()

bool QDebug::autoInsertSpaces ( ) const
inline

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

Since
5.0
See also
QDebugStateSaver

Definition at line 120 of file qdebug.h.

◆ maybeQuote()

QDebug & QDebug::maybeQuote ( char  c = '"')
inline
Since
5.4

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(), noquote()

Definition at line 125 of file qdebug.h.

◆ maybeSpace()

QDebug & QDebug::maybeSpace ( )
inline

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(), nospace()

Definition at line 114 of file qdebug.h.

◆ noquote()

QDebug & QDebug::noquote ( )
inline
Since
5.4

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(), maybeQuote()

Definition at line 124 of file qdebug.h.

Here is the caller graph for this function:

◆ nospace()

QDebug & QDebug::nospace ( )
inline

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

See also
space(), maybeSpace()

Definition at line 113 of file qdebug.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator<<() [1/27]

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

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

Definition at line 128 of file qdebug.h.

◆ operator<<() [2/27]

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

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

Definition at line 129 of file qdebug.h.

◆ operator<<() [3/27]

QDebug & QDebug::operator<< ( char16_t  t)
inline
Since
5.5

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

Definition at line 132 of file qdebug.h.

◆ operator<<() [4/27]

QDebug & QDebug::operator<< ( char32_t  t)
inline
Since
5.5

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

Definition at line 133 of file qdebug.h.

◆ operator<<() [5/27]

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

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.

Definition at line 142 of file qdebug.h.

Here is the call graph for this function:

◆ operator<<() [6/27]

QDebug & QDebug::operator<< ( const char16_t *  t)
inline
Since
6.0

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.

Definition at line 143 of file qdebug.h.

◆ operator<<() [7/27]

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

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:

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.

Definition at line 150 of file qdebug.h.

◆ operator<<() [8/27]

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

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:

Definition at line 145 of file qdebug.h.

◆ operator<<() [9/27]

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

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

Definition at line 152 of file qdebug.h.

◆ operator<<() [10/27]

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

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

Definition at line 141 of file qdebug.h.

◆ operator<<() [11/27]

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

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

Definition at line 140 of file qdebug.h.

◆ operator<<() [12/27]

QDebug & QDebug::operator<< ( QByteArrayView  t)
inline
Since
6.0

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.

Definition at line 151 of file qdebug.h.

◆ operator<<() [13/27]

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

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.

Definition at line 127 of file qdebug.h.

◆ operator<<() [14/27]

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

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

Definition at line 138 of file qdebug.h.

◆ operator<<() [15/27]

QDebug & QDebug::operator<< ( QLatin1String  t)
inline

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.

Definition at line 149 of file qdebug.h.

◆ operator<<() [16/27]

QDebug & QDebug::operator<< ( QStringView  s)
inline
Since
5.10

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.

Definition at line 147 of file qdebug.h.

◆ operator<<() [17/27]

QDebug & QDebug::operator<< ( QTextStreamFunction  f)
inline

Definition at line 154 of file qdebug.h.

◆ operator<<() [18/27]

QDebug & QDebug::operator<< ( QTextStreamManipulator  m)
inline

Definition at line 159 of file qdebug.h.

◆ operator<<() [19/27]

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

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

Definition at line 139 of file qdebug.h.

◆ operator<<() [20/27]

QDebug & QDebug::operator<< ( QUtf8StringView  s)
inline
Since
6.0

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.

Definition at line 148 of file qdebug.h.

◆ operator<<() [21/27]

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

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

Definition at line 134 of file qdebug.h.

◆ operator<<() [22/27]

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

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

Definition at line 136 of file qdebug.h.

◆ operator<<() [23/27]

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

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

Definition at line 130 of file qdebug.h.

◆ operator<<() [24/27]

QDebug & QDebug::operator<< ( std::nullptr_t  )
inline

Definition at line 153 of file qdebug.h.

◆ operator<<() [25/27]

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

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

Definition at line 135 of file qdebug.h.

◆ operator<<() [26/27]

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

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

Definition at line 137 of file qdebug.h.

◆ operator<<() [27/27]

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

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

Definition at line 131 of file qdebug.h.

◆ operator=()

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

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

Definition at line 202 of file qdebug.h.

◆ quote()

QDebug & QDebug::quote ( )
inline
Since
5.4

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(), maybeQuote()

Definition at line 123 of file qdebug.h.

◆ resetFormat()

QDebug & QDebug::resetFormat ( )

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

See also
space(), quote()
Since
5.4

Definition at line 401 of file qdebug.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setAutoInsertSpaces()

void QDebug::setAutoInsertSpaces ( bool  b)
inline

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

Since
5.0
See also
QDebugStateSaver

Definition at line 121 of file qdebug.h.

Here is the caller graph for this function:

◆ setVerbosity()

void QDebug::setVerbosity ( int  verbosityLevel)
inline
Since
5.6

Sets the verbosity of the stream to verbosityLevel.

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

See also
verbosity(), VerbosityLevel

Definition at line 117 of file qdebug.h.

◆ space()

QDebug & QDebug::space ( )
inline

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(), maybeSpace()

Definition at line 112 of file qdebug.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap()

QDebug::swap ( QDebug other)
inlinenoexcept
Since
5.0

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

Definition at line 108 of file qdebug.h.

Here is the call graph for this function:

◆ toString()

template<typename T >
template< class T > QString QDebug::toString ( T &&  object)
inlinestatic
Since
6.0

Definition at line 163 of file qdebug.h.

Here is the caller graph for this function:

◆ verbosity() [1/2]

int QDebug::verbosity ( ) const
inline
Since
5.6

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(), VerbosityLevel

Definition at line 116 of file qdebug.h.

◆ verbosity() [2/2]

QDebug & QDebug::verbosity ( int  verbosityLevel)
inline
Since
5.13

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(), VerbosityLevel

Definition at line 115 of file qdebug.h.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<() [1/15]

template< typename T > QDebug operator<< ( QDebug  debug,
const QContiguousCache< T > &  cache 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [2/15]

template< typename T > QDebug operator<< ( QDebug  debug,
const QFlags< T > &  flags 
)
related
Since
4.7

Writes flags to debug.

◆ operator<<() [3/15]

template< class Key, class T > QDebug operator<< ( QDebug  debug,
const QHash< Key, T > &  hash 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [4/15]

template< class T > QDebug operator<< ( QDebug  debug,
const QList< T > &  list 
)
related

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

Definition at line 202 of file qdebug.h.

Here is the call graph for this function:

◆ operator<<() [5/15]

template< class Key, class T > QDebug operator<< ( QDebug  debug,
const QMap< Key, T > &  map 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [6/15]

template< class Key, class T > QDebug operator<< ( QDebug  debug,
const QMultiHash< Key, T > &  hash 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [7/15]

template< class Key, class T > QDebug operator<< ( QDebug  debug,
const QMultiMap< Key, T > &  map 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [8/15]

template< class T1, class T2 > QDebug operator<< ( QDebug  debug,
const QPair< T1, T2 > &  pair 
)
related

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

◆ operator<<() [9/15]

template< typename T > QDebug operator<< ( QDebug  debug,
const QSet< T > &  set 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [10/15]

template< class T, qsizetype P > QDebug operator<< ( QDebug  debug,
const QVarLengthArray< T, P > &  array 
)
related
Since
6.3

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [11/15]

template< typename T, typename Alloc > QDebug operator<< ( QDebug  debug,
const std::list< T, Alloc > &  vec 
)
related
Since
5.7

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [12/15]

template< typename Key, typename T, typename Compare, typename Alloc > QDebug operator<< ( QDebug  debug,
const std::map< Key, T, Compare, Alloc > &  map 
)
related
Since
5.7

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [13/15]

template< typename Key, typename T, typename Compare, typename Alloc > QDebug operator<< ( QDebug  debug,
const std::multimap< Key, T, Compare, Alloc > &  map 
)
related
Since
5.7

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [14/15]

template< class T1, class T2 > QDebug operator<< ( QDebug  debug,
const std::pair< T1, T2 > &  pair 
)
related

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

Definition at line 202 of file qdebug.h.

◆ operator<<() [15/15]

template< typename T, typename Alloc > QDebug operator<< ( QDebug  debug,
const std::vector< T, Alloc > &  vec 
)
related
Since
5.7

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

Definition at line 202 of file qdebug.h.

◆ QDebugStateSaver

friend class QDebugStateSaver
friend

Definition at line 67 of file qdebug.h.

◆ QDebugStateSaverPrivate

friend class QDebugStateSaverPrivate
friend

Definition at line 68 of file qdebug.h.

◆ QMessageLogger

friend class QMessageLogger
friend

Definition at line 66 of file qdebug.h.


The documentation for this class was generated from the following files: