| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
| 4 |
** All rights reserved. |
| 5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
| 6 |
** |
| 7 |
** This file is part of the QtCore module of the Qt Toolkit. |
| 8 |
** |
| 9 |
** $QT_BEGIN_LICENSE:LGPL$ |
| 10 |
** No Commercial Usage |
| 11 |
** This file contains pre-release code and may not be distributed. |
| 12 |
** You may use this file in accordance with the terms and conditions |
| 13 |
** contained in the Technology Preview License Agreement accompanying |
| 14 |
** this package. |
| 15 |
** |
| 16 |
** GNU Lesser General Public License Usage |
| 17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
| 18 |
** General Public License version 2.1 as published by the Free Software |
| 19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
| 20 |
** packaging of this file. Please review the following information to |
| 21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
| 22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
| 23 |
** |
| 24 |
** In addition, as a special exception, Nokia gives you certain additional |
| 25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
| 26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
| 27 |
** |
| 28 |
** If you have questions regarding the use of this file, please contact |
| 29 |
** Nokia at qt-info@nokia.com. |
| 30 |
** |
| 31 |
** |
| 32 |
** |
| 33 |
** |
| 34 |
** |
| 35 |
** |
| 36 |
** |
| 37 |
** |
| 38 |
** $QT_END_LICENSE$ |
| 39 |
** |
| 40 |
****************************************************************************/ |
| 41 |
|
| 42 |
#ifdef QT_NO_DEBUG |
| 43 |
#undef QT_NO_DEBUG |
| 44 |
#endif |
| 45 |
#ifdef qDebug |
| 46 |
#undef qDebug |
| 47 |
#endif |
| 48 |
|
| 49 |
#include "qdebug.h" |
| 50 |
|
| 51 |
// This file is needed to force compilation of QDebug into the kernel library. |
| 52 |
|
| 53 |
/*! |
| 54 |
\class QDebug |
| 55 |
\ingroup io |
| 56 |
\mainclass |
| 57 |
\brief The QDebug class provides an output stream for debugging information. |
| 58 |
|
| 59 |
QDebug is used whenever the developer needs to write out debugging or tracing |
| 60 |
information to a device, file, string or console. |
| 61 |
|
| 62 |
\section1 Basic Use |
| 63 |
|
| 64 |
In the common case, it is useful to call the qDebug() function to obtain a |
| 65 |
default QDebug object to use for writing debugging information. |
| 66 |
|
| 67 |
\snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 1 |
| 68 |
|
| 69 |
This constructs a QDebug object using the constructor that accepts a QtMsgType |
| 70 |
value of QtDebugMsg. Similarly, the qWarning(), qCritical() and qFatal() |
| 71 |
functions also return QDebug objects for the corresponding message types. |
| 72 |
|
| 73 |
The class also provides several constructors for other situations, including |
| 74 |
a constructor that accepts a QFile or any other QIODevice subclass that is |
| 75 |
used to write debugging information to files and other devices. The constructor |
| 76 |
that accepts a QString is used to write to a string for display or serialization. |
| 77 |
|
| 78 |
\section1 Writing Custom Types to a Stream |
| 79 |
|
| 80 |
Many standard types can be written to QDebug objects, and Qt provides support for |
| 81 |
most Qt value types. To add support for custom types, you need to implement a |
| 82 |
streaming operator, as in the following example: |
| 83 |
|
| 84 |
\snippet doc/src/snippets/qdebug/qdebugsnippet.cpp 0 |
| 85 |
|
| 86 |
This is described in the \l{Debugging Techniques} and |
| 87 |
\l{Creating Custom Qt Types#Making the Type Printable}{Creating Custom Qt Types} |
| 88 |
documents. |
| 89 |
*/ |
| 90 |
|
| 91 |
/*! |
| 92 |
\fn QDebug::QDebug(QIODevice *device) |
| 93 |
|
| 94 |
Constructs a debug stream that writes to the given \a device. |
| 95 |
*/ |
| 96 |
|
| 97 |
/*! |
| 98 |
\fn QDebug::QDebug(QString *string) |
| 99 |
|
| 100 |
Constructs a debug stream that writes to the given \a string. |
| 101 |
*/ |
| 102 |
|
| 103 |
/*! |
| 104 |
\fn QDebug::QDebug(QtMsgType type) |
| 105 |
|
| 106 |
Constructs a debug stream that writes to the handler for the message type specified by \a type. |
| 107 |
*/ |
| 108 |
|
| 109 |
/*! |
| 110 |
\fn QDebug::QDebug(const QDebug &other) |
| 111 |
|
| 112 |
Constructs a copy of the \a other debug stream. |
| 113 |
*/ |
| 114 |
|
| 115 |
/*! |
| 116 |
\fn QDebug &QDebug::operator=(const QDebug &other) |
| 117 |
|
| 118 |
Assigns the \a other debug stream to this stream and returns a reference to |
| 119 |
this stream. |
| 120 |
*/ |
| 121 |
|
| 122 |
/*! |
| 123 |
\fn QDebug::~QDebug() |
| 124 |
|
| 125 |
Flushes any pending data to be written and destroys the debug stream. |
| 126 |
*/ |
| 127 |
|
| 128 |
/*! |
| 129 |
\fn QDebug &QDebug::space() |
| 130 |
|
| 131 |
Writes a space character to the debug stream and returns a reference to |
| 132 |
the stream. |
| 133 |
|
| 134 |
The stream will record that the last character sent to the stream was a |
| 135 |
space. |
| 136 |
|
| 137 |
\sa nospace(), maybeSpace() |
| 138 |
*/ |
| 139 |
|
| 140 |
/*! |
| 141 |
\fn QDebug &QDebug::nospace() |
| 142 |
|
| 143 |
Clears the stream's internal flag that records whether the last character |
| 144 |
was a space and returns a reference to the stream. |
| 145 |
|
| 146 |
\sa space(), maybeSpace() |
| 147 |
*/ |
| 148 |
|
| 149 |
/*! |
| 150 |
\fn QDebug &QDebug::maybeSpace() |
| 151 |
|
| 152 |
Writes a space character to the debug stream, depending on the last |
| 153 |
character sent to the stream, and returns a reference to the stream. |
| 154 |
|
| 155 |
If the last character was a space character, this function writes a space |
| 156 |
character to the stream; otherwise, no characters are written to the stream. |
| 157 |
|
| 158 |
\sa space(), nospace() |
| 159 |
*/ |
| 160 |
|
| 161 |
/*! |
| 162 |
\fn QDebug &QDebug::operator<<(QChar t) |
| 163 |
|
| 164 |
Writes the character, \a t, to the stream and returns a reference to the |
| 165 |
stream. |
| 166 |
*/ |
| 167 |
|
| 168 |
/*! |
| 169 |
\fn QDebug &QDebug::operator<<(QBool t) |
| 170 |
\internal |
| 171 |
|
| 172 |
Writes the boolean value, \a t, to the stream and returns a reference to the |
| 173 |
stream. |
| 174 |
*/ |
| 175 |
|
| 176 |
/*! |
| 177 |
\fn QDebug &QDebug::operator<<(bool t) |
| 178 |
|
| 179 |
Writes the boolean value, \a t, to the stream and returns a reference to the |
| 180 |
stream. |
| 181 |
*/ |
| 182 |
|
| 183 |
/*! |
| 184 |
\fn QDebug &QDebug::operator<<(char t) |
| 185 |
|
| 186 |
Writes the character, \a t, to the stream and returns a reference to the |
| 187 |
stream. |
| 188 |
*/ |
| 189 |
|
| 190 |
/*! |
| 191 |
\fn QDebug &QDebug::operator<<(signed short i) |
| 192 |
|
| 193 |
Writes the signed short integer, \a i, to the stream and returns a reference |
| 194 |
to the stream. |
| 195 |
*/ |
| 196 |
|
| 197 |
/*! |
| 198 |
\fn QDebug &QDebug::operator<<(unsigned short i) |
| 199 |
|
| 200 |
Writes then unsigned short integer, \a i, to the stream and returns a |
| 201 |
reference to the stream. |
| 202 |
*/ |
| 203 |
|
| 204 |
/*! |
| 205 |
\fn QDebug &QDebug::operator<<(signed int i) |
| 206 |
|
| 207 |
Writes the signed integer, \a i, to the stream and returns a reference |
| 208 |
to the stream. |
| 209 |
*/ |
| 210 |
|
| 211 |
/*! |
| 212 |
\fn QDebug &QDebug::operator<<(unsigned int i) |
| 213 |
|
| 214 |
Writes then unsigned integer, \a i, to the stream and returns a reference to |
| 215 |
the stream. |
| 216 |
*/ |
| 217 |
|
| 218 |
/*! |
| 219 |
\fn QDebug &QDebug::operator<<(signed long l) |
| 220 |
|
| 221 |
Writes the signed long integer, \a l, to the stream and returns a reference |
| 222 |
to the stream. |
| 223 |
*/ |
| 224 |
|
| 225 |
/*! |
| 226 |
\fn QDebug &QDebug::operator<<(unsigned long l) |
| 227 |
|
| 228 |
Writes then unsigned long integer, \a l, to the stream and returns a reference |
| 229 |
to the stream. |
| 230 |
*/ |
| 231 |
|
| 232 |
/*! |
| 233 |
\fn QDebug &QDebug::operator<<(qint64 i) |
| 234 |
|
| 235 |
Writes the signed 64-bit integer, \a i, to the stream and returns a reference |
| 236 |
to the stream. |
| 237 |
*/ |
| 238 |
|
| 239 |
/*! |
| 240 |
\fn QDebug &QDebug::operator<<(quint64 i) |
| 241 |
|
| 242 |
Writes then unsigned 64-bit integer, \a i, to the stream and returns a |
| 243 |
reference to the stream. |
| 244 |
*/ |
| 245 |
|
| 246 |
/*! |
| 247 |
\fn QDebug &QDebug::operator<<(float f) |
| 248 |
|
| 249 |
Writes the 32-bit floating point number, \a f, to the stream and returns a |
| 250 |
reference to the stream. |
| 251 |
*/ |
| 252 |
|
| 253 |
/*! |
| 254 |
\fn QDebug &QDebug::operator<<(double f) |
| 255 |
|
| 256 |
Writes the 64-bit floating point number, \a f, to the stream and returns a |
| 257 |
reference to the stream. |
| 258 |
*/ |
| 259 |
|
| 260 |
/*! |
| 261 |
\fn QDebug &QDebug::operator<<(const char *s) |
| 262 |
|
| 263 |
Writes the '\0'-terminated string, \a s, to the stream and returns a |
| 264 |
reference to the stream. |
| 265 |
*/ |
| 266 |
|
| 267 |
/*! |
| 268 |
\fn QDebug &QDebug::operator<<(const QString &s) |
| 269 |
|
| 270 |
Writes the string, \a s, to the stream and returns a reference to the stream. |
| 271 |
*/ |
| 272 |
|
| 273 |
/*! |
| 274 |
\fn QDebug &QDebug::operator<<(const QStringRef &s) |
| 275 |
|
| 276 |
Writes the string reference, \a s, to the stream and returns a reference to |
| 277 |
the stream. |
| 278 |
*/ |
| 279 |
|
| 280 |
/*! |
| 281 |
\fn QDebug &QDebug::operator<<(const QLatin1String &s) |
| 282 |
|
| 283 |
Writes the Latin1-encoded string, \a s, to the stream and returns a reference |
| 284 |
to the stream. |
| 285 |
*/ |
| 286 |
|
| 287 |
/*! |
| 288 |
\fn QDebug &QDebug::operator<<(const QByteArray &b) |
| 289 |
|
| 290 |
Writes the byte array, \a b, to the stream and returns a reference to the |
| 291 |
stream. |
| 292 |
*/ |
| 293 |
|
| 294 |
/*! |
| 295 |
\fn QDebug &QDebug::operator<<(const void *p) |
| 296 |
|
| 297 |
Writes a pointer, \a p, to the stream and returns a reference to the stream. |
| 298 |
*/ |
| 299 |
|
| 300 |
/*! |
| 301 |
\fn QDebug &QDebug::operator<<(QTextStreamFunction f) |
| 302 |
\internal |
| 303 |
*/ |
| 304 |
|
| 305 |
/*! |
| 306 |
\fn QDebug &QDebug::operator<<(QTextStreamManipulator m) |
| 307 |
\internal |
| 308 |
*/ |