CopperSpice API  1.7.2
QDebug Class Reference

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

Public Methods

 QDebug (const QDebug &other)
 
 QDebug (QIODevice *device)
 
 QDebug (QString *string)
 
 QDebug (QtMsgType type)
 
 ~QDebug ()
 
bool autoInsertSpaces () const
 
QDebug & maybeQuote (char c= '"')
 
QDebug & maybeSpace ()
 
QDebug & noquote ()
 
QDebug & nospace ()
 
QDebug & operator<< (bool value)
 
QDebug & operator<< (char value)
 
QDebug & operator<< (char16_t value)
 
QDebug & operator<< (char32_t value)
 
QDebug & operator<< (const char *value)
 
QDebug & operator<< (const QByteArray &str)
 
QDebug & operator<< (const QString &str)
 
QDebug & operator<< (const void *ptr)
 
QDebug & operator<< (double value)
 
QDebug & operator<< (float value)
 
QDebug & operator<< (QChar value)
 
QDebug & operator<< (qint64 value)
 
QDebug & operator<< (QStringView str)
 
QDebug & operator<< (quint64 value)
 
QDebug & operator<< (signed int value)
 
QDebug & operator<< (signed long value)
 
QDebug & operator<< (signed short value)
 
QDebug & operator<< (unsigned int value)
 
QDebug & operator<< (unsigned long value)
 
QDebug & operator<< (unsigned short value)
 
QDebug & operator= (const QDebug &other)
 
QDebug & quote ()
 
QDebug & resetFormat ()
 
void setAutoInsertSpaces (bool b)
 
void setVerbosity (int verbosityLevel)
 
QDebug & space ()
 
void swap (QDebug &other)
 
int verbosity () const
 

Detailed Description

The QDebug class provides an output stream for debugging information. QDebug is used whenever the developer needs to write out debugging or tracing information to a device, file, string or console.

Basic Operations

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() << "Date:" << QDate::currentDate();
qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40);
qDebug() << "Custom coordinate type:" << 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.

Writing Custom Types to a Stream

Many standard types can be written to QDebug objects, and CopperSpice provides support for most CopperSpice value types. To add support for custom types, you need to implement a streaming operator, as in the following example:

QDebug operator<<(QDebug dbg, const Coordinate &value) {
dbg.nospace() << "(" << value.x() << ", " << value.y() << ")";
return dbg.space();
}

This is described in Creating Custom Types.

See also
space(), nospace()

Constructor & Destructor Documentation

QDebug::QDebug ( QIODevice device)
inline

Constructs a debug stream that writes to the given device.

QDebug::QDebug ( QString string)
inline

Constructs a debug stream that writes to the given string.

QDebug::QDebug ( QtMsgType  type)
inline

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

QDebug::QDebug ( const QDebug &  other)
inline

Constructs a copy of the other debug stream.

QDebug::~QDebug ( )

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

Method Documentation

bool QDebug::autoInsertSpaces ( ) const
inline

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

See also
setAutoInsertSpaces(), QDebugStateSaver
QDebug & QDebug::maybeQuote ( char  c = '"')
inline

Writes a character c to the debug stream, depending on the current setting for automatic insertion of quotes. Returns a reference to the stream. The default character is a double quote.

See also
quote(), noquote()
QDebug & QDebug::maybeSpace ( )
inline

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

See also
space(), nospace()
QDebug & QDebug::noquote ( )
inline

Disables automatic insertion of quotation characters around QChar, QString and QByteArray contents. 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()
QDebug & QDebug::nospace ( )
inline

Disables automatic insertion of spaces. Returns a reference to the stream.

See also
space(), maybeSpace()
QDebug & QDebug::operator<< ( bool  value)
inline

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

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

Writes the character value to the stream and returns a reference to the stream.

QDebug & QDebug::operator<< ( char16_t  value)
inline

Writes the 16-bit character value to the stream and returns a reference to the stream.

QDebug & QDebug::operator<< ( char32_t  value)
inline

Writes the 32-bit character value to the stream and returns a reference to the stream.

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

Writes the null terminated string value to the stream and returns a reference to the stream.

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

Writes the byte array str to the stream and returns a reference to the stream.

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

Writes the string str to the stream and returns a reference to the stream.

QDebug & QDebug::operator<< ( const void *  ptr)
inline

Writes a pointer ptr to the stream and returns a reference to the stream.

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

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

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

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

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

Writes the character value to the stream and returns a reference to the stream.

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

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

QDebug & QDebug::operator<< ( QStringView  str)
inline

Writes the string view str to the stream and returns a reference to the stream.

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

Writes the unsigned 64-bit integer value to the stream and returns a reference to the stream.

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

Writes the signed integer value to the stream and returns a reference to the stream.

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

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

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

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

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

Writes the unsigned integer value to the stream and returns a reference to the stream.

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

Writes the unsigned long integer value to the stream and returns a reference to the stream.

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

Writes the unsigned short integer value to the stream and returns a reference to the stream.

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

Copy assigns from other and returns a reference to this object.

QDebug & QDebug::quote ( )
inline

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()
QDebug & QDebug::resetFormat ( )

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

See also
space(), quote()
void QDebug::setAutoInsertSpaces ( bool  b)
inline

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

See also
autoInsertSpaces(), QDebugStateSaver
void QDebug::setVerbosity ( int  verbosityLevel)
inline

Sets the verbosity of the stream to verbosityLevel. The allowed range is from 0 to 7. The default value is 2.

See also
verbosity()
QDebug & QDebug::space ( )
inline

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

See also
nospace(), maybeSpace()
void QDebug::swap ( QDebug &  other)
inline

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

int QDebug::verbosity ( ) const
inline

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