CopperSpice API  1.9.1
QDebug Class Reference

The QDebug class generates output for debugging. 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 QUrl &url)
 
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 enable)
 
void setVerbosity (int verbosityLevel)
 
QDebug & space ()
 
void swap (QDebug &other)
 
int verbosity () const
 

Detailed Description

The QDebug class generates output for debugging. This class is intended to be used during the application development process. The debug output stream is normally displayed on the terminal screen. The output can be redirected to a file.

Constructors

There are three different constructors for QDebug to accept a QIODevice, a QString, or a QtMsgType.

A QFile object can be used to construct a QDebug since QFile inherits from QIODevice. Any other class which inherits from QIODevice will also call this constructor. Passing a QString to QDebug will call the appropriate constructor. This can be used to format the output of the given debug message.

Debug Output

The qDebug() function calls a constructor in the QDebug class. Using this function is a common and useful way to display debug output as shown in the following examples.

qDebug() << "Current date = " << today;
QRect rectangle = widget->geometry();
qDebug() << "Window Geometry = " << rectangle;
QVector<int> data = { 5, 17, 32 };
qDebug() << "Vector size =" << data.size();

Writing Custom Types to a Stream

Any data type can be written to QDebug. CopperSpice provides built in support for the most common data types. To add support for custom types you will need to implement an operator<<() function as shown in the following example.

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

Redirect Output

The debug output can be redirected from the screen (terminal window) to a file by using the following command line syntax.

[your-program-name] 2> filename.txt

Enable Additional Debug Messages

An extensive number of calls to qDebug() can be found within the CopperSpice libraries. They are all disabled by default. Each call to qDebug() is guarded with #define macro. For ease of use the debug messages have been grouped into a small number of categories.The full list of #define macros can be found in the CsCore library in the src/core/global/qglobal_debug.h header file.

To enable one or more of the debug macros either uncomment in the header file or pass one or more of the defines in your CopperSpice build files.

// partial list of debug macros
#define CS_SHOW_DEBUG_CORE
#define CS_SHOW_DEBUG_GUI
#define CS_SHOW_DEBUG_GUI_PAINTING
#define CS_SHOW_DEBUG_GUI_WIDGETS
#define CS_SHOW_DEBUG_NETWORK

The following is an example which can be found in CsCore. If the macro is enabled then the debug message will be displayed in the terminal window.

#if defined(CS_SHOW_DEBUG_CORE)
qDebug("QFSFileEngine::open() No file name was specified");
#endif
See also
Creating Custom Types

Constructor & Destructor Documentation

QDebug::QDebug ( QIODevice device)
inline

Constructs a debug stream which writes to the given device.

QDebug::QDebug ( QString string)
inline

Constructs a debug stream which writes to the given string.

QDebug::QDebug ( QtMsgType  type)
inline

Constructs a debug stream 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 given boolean 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 QUrl url)
inline

Writes the url 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  enable)
inline

Enables automatic insertion of spaces between writes if enable 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 more information is desired. The allowed range is from 0 to 7. The default value is 2.

See also
setVerbosity()