| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qdebug.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Copyright (C) 2014 Intel Corporation. | - | ||||||||||||||||||||||||
| 5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 6 | ** | - | ||||||||||||||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 8 | ** | - | ||||||||||||||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 17 | ** | - | ||||||||||||||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 26 | ** | - | ||||||||||||||||||||||||
| 27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 30 | ** | - | ||||||||||||||||||||||||
| 31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 32 | ** | - | ||||||||||||||||||||||||
| 33 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | #ifdef QT_NO_DEBUG | - | ||||||||||||||||||||||||
| 36 | #undef QT_NO_DEBUG | - | ||||||||||||||||||||||||
| 37 | #endif | - | ||||||||||||||||||||||||
| 38 | #ifdef qDebug | - | ||||||||||||||||||||||||
| 39 | #undef qDebug | - | ||||||||||||||||||||||||
| 40 | #endif | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | #include "qdebug.h" | - | ||||||||||||||||||||||||
| 43 | #include "qmetaobject.h" | - | ||||||||||||||||||||||||
| 44 | #include <private/qtextstream_p.h> | - | ||||||||||||||||||||||||
| 45 | #include <private/qtools_p.h> | - | ||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 48 | - | |||||||||||||||||||||||||
| 49 | using QtMiscUtils::toHexUpper; | - | ||||||||||||||||||||||||
| 50 | using QtMiscUtils::fromHex; | - | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | // This file is needed to force compilation of QDebug into the kernel library. | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | /*! | - | ||||||||||||||||||||||||
| 55 | \class QDebug | - | ||||||||||||||||||||||||
| 56 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 57 | \ingroup shared | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | \brief The QDebug class provides an output stream for debugging information. | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | QDebug is used whenever the developer needs to write out debugging or tracing | - | ||||||||||||||||||||||||
| 62 | information to a device, file, string or console. | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | \section1 Basic Use | - | ||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | In the common case, it is useful to call the qDebug() function to obtain a | - | ||||||||||||||||||||||||
| 67 | default QDebug object to use for writing debugging information. | - | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | \snippet qdebug/qdebugsnippet.cpp 1 | - | ||||||||||||||||||||||||
| 70 | - | |||||||||||||||||||||||||
| 71 | This constructs a QDebug object using the constructor that accepts a QtMsgType | - | ||||||||||||||||||||||||
| 72 | value of QtDebugMsg. Similarly, the qWarning(), qCritical() and qFatal() | - | ||||||||||||||||||||||||
| 73 | functions also return QDebug objects for the corresponding message types. | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | The class also provides several constructors for other situations, including | - | ||||||||||||||||||||||||
| 76 | a constructor that accepts a QFile or any other QIODevice subclass that is | - | ||||||||||||||||||||||||
| 77 | used to write debugging information to files and other devices. The constructor | - | ||||||||||||||||||||||||
| 78 | that accepts a QString is used to write to a string for display or serialization. | - | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | \section1 Formatting Options | - | ||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||
| 82 | QDebug formats output so that it's easily readable. It automatically adds spaces | - | ||||||||||||||||||||||||
| 83 | between arguments, and adds quotes around QString, QByteArray, QChar arguments. | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | You can tweak these options through the space(), nospace() and quote(), noquote() | - | ||||||||||||||||||||||||
| 86 | methods. Furthermore, \l{QTextStream manipulators} can be piped into a QDebug | - | ||||||||||||||||||||||||
| 87 | stream. | - | ||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | QDebugStateSaver limits changes to the formatting to the current scope. | - | ||||||||||||||||||||||||
| 90 | resetFormat() resets the options to the default ones. | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | \section1 Writing Custom Types to a Stream | - | ||||||||||||||||||||||||
| 93 | - | |||||||||||||||||||||||||
| 94 | Many standard types can be written to QDebug objects, and Qt provides support for | - | ||||||||||||||||||||||||
| 95 | most Qt value types. To add support for custom types, you need to implement a | - | ||||||||||||||||||||||||
| 96 | streaming operator, as in the following example: | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | \snippet qdebug/qdebugsnippet.cpp 0 | - | ||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | This is described in the \l{Debugging Techniques} and | - | ||||||||||||||||||||||||
| 101 | \l{Creating Custom Qt Types#Making the Type Printable}{Creating Custom Qt Types} | - | ||||||||||||||||||||||||
| 102 | documents. | - | ||||||||||||||||||||||||
| 103 | */ | - | ||||||||||||||||||||||||
| 104 | - | |||||||||||||||||||||||||
| 105 | /*! | - | ||||||||||||||||||||||||
| 106 | \fn QDebug::QDebug(QIODevice *device) | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | Constructs a debug stream that writes to the given \a device. | - | ||||||||||||||||||||||||
| 109 | */ | - | ||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | /*! | - | ||||||||||||||||||||||||
| 112 | \fn QDebug::QDebug(QString *string) | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | Constructs a debug stream that writes to the given \a string. | - | ||||||||||||||||||||||||
| 115 | */ | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | /*! | - | ||||||||||||||||||||||||
| 118 | \fn QDebug::QDebug(QtMsgType type) | - | ||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | Constructs a debug stream that writes to the handler for the message type specified by \a type. | - | ||||||||||||||||||||||||
| 121 | */ | - | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | /*! | - | ||||||||||||||||||||||||
| 124 | \fn QDebug::QDebug(const QDebug &other) | - | ||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | Constructs a copy of the \a other debug stream. | - | ||||||||||||||||||||||||
| 127 | */ | - | ||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | /*! | - | ||||||||||||||||||||||||
| 130 | \fn QDebug &QDebug::operator=(const QDebug &other) | - | ||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | Assigns the \a other debug stream to this stream and returns a reference to | - | ||||||||||||||||||||||||
| 133 | this stream. | - | ||||||||||||||||||||||||
| 134 | */ | - | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | /*! | - | ||||||||||||||||||||||||
| 137 | \fn QDebug::~QDebug() | - | ||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | Flushes any pending data to be written and destroys the debug stream. | - | ||||||||||||||||||||||||
| 140 | */ | - | ||||||||||||||||||||||||
| 141 | // Has been defined in the header / inlined before Qt 5.4 | - | ||||||||||||||||||||||||
| 142 | QDebug::~QDebug() | - | ||||||||||||||||||||||||
| 143 | { | - | ||||||||||||||||||||||||
| 144 | if (!--stream->ref) {
| 3734-15460 | ||||||||||||||||||||||||
| 145 | if (stream->space && stream->buffer.endsWith(QLatin1Char(' ')))
| 254-15173 | ||||||||||||||||||||||||
| 146 | stream->buffer.chop(1); executed 14919 times by 61 tests: stream->buffer.chop(1);Executed by:
| 14919 | ||||||||||||||||||||||||
| 147 | if (stream->message_output) {
| 351-15109 | ||||||||||||||||||||||||
| 148 | qt_message_output(stream->type, | - | ||||||||||||||||||||||||
| 149 | stream->context, | - | ||||||||||||||||||||||||
| 150 | stream->buffer); | - | ||||||||||||||||||||||||
| 151 | } executed 15109 times by 66 tests: end of blockExecuted by:
| 15109 | ||||||||||||||||||||||||
| 152 | delete stream; | - | ||||||||||||||||||||||||
| 153 | } executed 15460 times by 71 tests: end of blockExecuted by:
| 15460 | ||||||||||||||||||||||||
| 154 | } executed 19194 times by 71 tests: end of blockExecuted by:
| 19194 | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | /*! | - | ||||||||||||||||||||||||
| 157 | \internal | - | ||||||||||||||||||||||||
| 158 | */ | - | ||||||||||||||||||||||||
| 159 | void QDebug::putUcs4(uint ucs4) | - | ||||||||||||||||||||||||
| 160 | { | - | ||||||||||||||||||||||||
| 161 | maybeQuote('\''); | - | ||||||||||||||||||||||||
| 162 | if (ucs4 < 0x20) {
| 1-7 | ||||||||||||||||||||||||
| 163 | stream->ts << "\\x" << hex << ucs4 << reset; | - | ||||||||||||||||||||||||
| 164 | } else if (ucs4 < 0x80) { executed 1 time by 1 test: end of blockExecuted by:
| 1-5 | ||||||||||||||||||||||||
| 165 | stream->ts << char(ucs4); | - | ||||||||||||||||||||||||
| 166 | } else { executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 167 | if (ucs4 < 0x10000)
| 0-2 | ||||||||||||||||||||||||
| 168 | stream->ts << "\\u" << qSetFieldWidth(4); executed 2 times by 1 test: stream->ts << "\\u" << qSetFieldWidth(4);Executed by:
| 2 | ||||||||||||||||||||||||
| 169 | else | - | ||||||||||||||||||||||||
| 170 | stream->ts << "\\U" << qSetFieldWidth(8); never executed: stream->ts << "\\U" << qSetFieldWidth(8); | 0 | ||||||||||||||||||||||||
| 171 | stream->ts << hex << qSetPadChar(QLatin1Char('0')) << ucs4 << reset; | - | ||||||||||||||||||||||||
| 172 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 173 | maybeQuote('\''); | - | ||||||||||||||||||||||||
| 174 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | // These two functions return true if the character should be printed by QDebug. | - | ||||||||||||||||||||||||
| 177 | // For QByteArray, this is technically identical to US-ASCII isprint(); | - | ||||||||||||||||||||||||
| 178 | // for QString, we use QChar::isPrint, which requires a full UCS-4 decode. | - | ||||||||||||||||||||||||
| 179 | static inline bool isPrintable(uint ucs4) | - | ||||||||||||||||||||||||
| 180 | { executed 3 times by 1 test: return QChar::isPrint(ucs4); }return QChar::isPrint(ucs4);Executed by:
executed 3 times by 1 test: return QChar::isPrint(ucs4);Executed by:
| 3 | ||||||||||||||||||||||||
| 181 | static inline bool isPrintable(ushort uc) | - | ||||||||||||||||||||||||
| 182 | { executed 202605 times by 33 tests: return QChar::isPrint(uc); }return QChar::isPrint(uc);Executed by:
executed 202605 times by 33 tests: return QChar::isPrint(uc);Executed by:
| 202605 | ||||||||||||||||||||||||
| 183 | static inline bool isPrintable(uchar c) | - | ||||||||||||||||||||||||
| 184 | { executed 173 times by 3 tests: return c >= ' ' && c < 0x7f;Executed by:
executed 173 times by 3 tests: return c >= ' ' && c < 0x7f;Executed by:
| 2-173 | ||||||||||||||||||||||||
| 185 | - | |||||||||||||||||||||||||
| 186 | template <typename Char> | - | ||||||||||||||||||||||||
| 187 | static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, int length, bool isUnicode = true) | - | ||||||||||||||||||||||||
| 188 | { | - | ||||||||||||||||||||||||
| 189 | QChar quote(QLatin1Char('"')); | - | ||||||||||||||||||||||||
| 190 | d->write("e, 1); | - | ||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||
| 192 | bool lastWasHexEscape = false; | - | ||||||||||||||||||||||||
| 193 | const Char *end = begin + length; | - | ||||||||||||||||||||||||
| 194 | for (const Char *p = begin; p != end; ++p) {
| 13176-17498 | ||||||||||||||||||||||||
| 195 | // check if we need to insert "" to break an hex escape sequence | - | ||||||||||||||||||||||||
| 196 | if (Q_UNLIKELY(lastWasHexEscape)) {
| 5-17493 | ||||||||||||||||||||||||
| 197 | if (fromHex(*p) != -1) {
| 1-4 | ||||||||||||||||||||||||
| 198 | // yes, insert it | - | ||||||||||||||||||||||||
| 199 | QChar quotes[] = { QLatin1Char('"'), QLatin1Char('"') }; | - | ||||||||||||||||||||||||
| 200 | d->write(quotes, 2); | - | ||||||||||||||||||||||||
| 201 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 202 | lastWasHexEscape = false; | - | ||||||||||||||||||||||||
| 203 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | if (sizeof(Char) == sizeof(QChar)) {
| 173-17325 | ||||||||||||||||||||||||
| 206 | // Surrogate characters are category Cs (Other_Surrogate), so isPrintable = false for them | - | ||||||||||||||||||||||||
| 207 | int runLength = 0; | - | ||||||||||||||||||||||||
| 208 | while (p + runLength != end &&
| 13114-202605 | ||||||||||||||||||||||||
| 209 | isPrintable(p[runLength]) && p[runLength] != '\\' && p[runLength] != '"')
| 111-202494 | ||||||||||||||||||||||||
| 210 | ++runLength; executed 198394 times by 33 tests: ++runLength;Executed by:
| 198394 | ||||||||||||||||||||||||
| 211 | if (runLength) {
| 2257-15068 | ||||||||||||||||||||||||
| 212 | d->write(reinterpret_cast<const QChar *>(p), runLength); | - | ||||||||||||||||||||||||
| 213 | p += runLength - 1; | - | ||||||||||||||||||||||||
| 214 | continue; executed 15068 times by 33 tests: continue;Executed by:
| 15068 | ||||||||||||||||||||||||
| 215 | } | - | ||||||||||||||||||||||||
| 216 | } else if (isPrintable(*p) && *p != '\\' && *p != '"') { executed 2257 times by 4 tests: end of blockExecuted by:
| 2-2257 | ||||||||||||||||||||||||
| 217 | QChar c = QLatin1Char(*p); | - | ||||||||||||||||||||||||
| 218 | d->write(&c, 1); | - | ||||||||||||||||||||||||
| 219 | continue; executed 158 times by 3 tests: continue;Executed by:
| 158 | ||||||||||||||||||||||||
| 220 | } | - | ||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | // print as an escape sequence (maybe, see below for surrogate pairs) | - | ||||||||||||||||||||||||
| 223 | int buflen = 2; | - | ||||||||||||||||||||||||
| 224 | ushort buf[sizeof "\\U12345678" - 1]; | - | ||||||||||||||||||||||||
| 225 | buf[0] = '\\'; | - | ||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | switch (*p) { | - | ||||||||||||||||||||||||
| 228 | case '"': executed 288 times by 4 tests: case '"':Executed by:
| 288 | ||||||||||||||||||||||||
| 229 | case '\\': executed 1914 times by 2 tests: case '\\':Executed by:
| 1914 | ||||||||||||||||||||||||
| 230 | buf[1] = *p; | - | ||||||||||||||||||||||||
| 231 | break; executed 2202 times by 4 tests: break;Executed by:
| 2202 | ||||||||||||||||||||||||
| 232 | case '\b': never executed: case '\b': | 0 | ||||||||||||||||||||||||
| 233 | buf[1] = 'b'; | - | ||||||||||||||||||||||||
| 234 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 235 | case '\f': never executed: case '\f': | 0 | ||||||||||||||||||||||||
| 236 | buf[1] = 'f'; | - | ||||||||||||||||||||||||
| 237 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 238 | case '\n': executed 52 times by 2 tests: case '\n':Executed by:
| 52 | ||||||||||||||||||||||||
| 239 | buf[1] = 'n'; | - | ||||||||||||||||||||||||
| 240 | break; executed 52 times by 2 tests: break;Executed by:
| 52 | ||||||||||||||||||||||||
| 241 | case '\r': never executed: case '\r': | 0 | ||||||||||||||||||||||||
| 242 | buf[1] = 'r'; | - | ||||||||||||||||||||||||
| 243 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 244 | case '\t': executed 1 time by 1 test: case '\t':Executed by:
| 1 | ||||||||||||||||||||||||
| 245 | buf[1] = 't'; | - | ||||||||||||||||||||||||
| 246 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||
| 247 | default: executed 17 times by 1 test: default:Executed by:
| 17 | ||||||||||||||||||||||||
| 248 | if (!isUnicode) {
| 5-12 | ||||||||||||||||||||||||
| 249 | // print as hex escape | - | ||||||||||||||||||||||||
| 250 | buf[1] = 'x'; | - | ||||||||||||||||||||||||
| 251 | buf[2] = toHexUpper(uchar(*p) >> 4); | - | ||||||||||||||||||||||||
| 252 | buf[3] = toHexUpper(uchar(*p)); | - | ||||||||||||||||||||||||
| 253 | buflen = 4; | - | ||||||||||||||||||||||||
| 254 | lastWasHexEscape = true; | - | ||||||||||||||||||||||||
| 255 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||||||||
| 256 | } | - | ||||||||||||||||||||||||
| 257 | if (QChar::isHighSurrogate(*p)) {
| 5-7 | ||||||||||||||||||||||||
| 258 | if ((p + 1) != end && QChar::isLowSurrogate(p[1])) {
| 1-4 | ||||||||||||||||||||||||
| 259 | // properly-paired surrogates | - | ||||||||||||||||||||||||
| 260 | uint ucs4 = QChar::surrogateToUcs4(*p, p[1]); | - | ||||||||||||||||||||||||
| 261 | if (isPrintable(ucs4)) {
| 1-2 | ||||||||||||||||||||||||
| 262 | buf[0] = *p; | - | ||||||||||||||||||||||||
| 263 | buf[1] = p[1]; | - | ||||||||||||||||||||||||
| 264 | buflen = 2; | - | ||||||||||||||||||||||||
| 265 | } else { executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 266 | buf[1] = 'U'; | - | ||||||||||||||||||||||||
| 267 | buf[2] = '0'; // toHexUpper(ucs4 >> 32); | - | ||||||||||||||||||||||||
| 268 | buf[3] = '0'; // toHexUpper(ucs4 >> 28); | - | ||||||||||||||||||||||||
| 269 | buf[4] = toHexUpper(ucs4 >> 20); | - | ||||||||||||||||||||||||
| 270 | buf[5] = toHexUpper(ucs4 >> 16); | - | ||||||||||||||||||||||||
| 271 | buf[6] = toHexUpper(ucs4 >> 12); | - | ||||||||||||||||||||||||
| 272 | buf[7] = toHexUpper(ucs4 >> 8); | - | ||||||||||||||||||||||||
| 273 | buf[8] = toHexUpper(ucs4 >> 4); | - | ||||||||||||||||||||||||
| 274 | buf[9] = toHexUpper(ucs4); | - | ||||||||||||||||||||||||
| 275 | buflen = 10; | - | ||||||||||||||||||||||||
| 276 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 277 | ++p; | - | ||||||||||||||||||||||||
| 278 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||||||||
| 279 | } | - | ||||||||||||||||||||||||
| 280 | // improperly-paired surrogates, fall through | - | ||||||||||||||||||||||||
| 281 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 282 | buf[1] = 'u'; | - | ||||||||||||||||||||||||
| 283 | buf[2] = toHexUpper(ushort(*p) >> 12); | - | ||||||||||||||||||||||||
| 284 | buf[3] = toHexUpper(ushort(*p) >> 8); | - | ||||||||||||||||||||||||
| 285 | buf[4] = toHexUpper(*p >> 4); | - | ||||||||||||||||||||||||
| 286 | buf[5] = toHexUpper(*p); | - | ||||||||||||||||||||||||
| 287 | buflen = 6; | - | ||||||||||||||||||||||||
| 288 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 289 | d->write(reinterpret_cast<QChar *>(buf), buflen); | - | ||||||||||||||||||||||||
| 290 | } executed 2272 times by 4 tests: end of blockExecuted by:
| 2272 | ||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||
| 292 | d->write("e, 1); | - | ||||||||||||||||||||||||
| 293 | } executed 13176 times by 35 tests: end of blockExecuted by:
| 13176 | ||||||||||||||||||||||||
| 294 | - | |||||||||||||||||||||||||
| 295 | /*! | - | ||||||||||||||||||||||||
| 296 | \internal | - | ||||||||||||||||||||||||
| 297 | Duplicated from QtTest::toPrettyUnicode(). | - | ||||||||||||||||||||||||
| 298 | */ | - | ||||||||||||||||||||||||
| 299 | void QDebug::putString(const QChar *begin, size_t length) | - | ||||||||||||||||||||||||
| 300 | { | - | ||||||||||||||||||||||||
| 301 | if (stream->testFlag(Stream::NoQuotes)) {
| 1624-13159 | ||||||||||||||||||||||||
| 302 | // no quotes, write the string directly too (no pretty-printing) | - | ||||||||||||||||||||||||
| 303 | // this respects the QTextStream state, though | - | ||||||||||||||||||||||||
| 304 | stream->ts.d_ptr->putString(begin, int(length)); | - | ||||||||||||||||||||||||
| 305 | } else { executed 1624 times by 10 tests: end of blockExecuted by:
| 1624 | ||||||||||||||||||||||||
| 306 | // we'll reset the QTextStream formatting mechanisms, so save the state | - | ||||||||||||||||||||||||
| 307 | QDebugStateSaver saver(*this); | - | ||||||||||||||||||||||||
| 308 | stream->ts.d_ptr->params.reset(); | - | ||||||||||||||||||||||||
| 309 | putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const ushort *>(begin), int(length)); | - | ||||||||||||||||||||||||
| 310 | } executed 13159 times by 34 tests: end of blockExecuted by:
| 13159 | ||||||||||||||||||||||||
| 311 | } | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | /*! | - | ||||||||||||||||||||||||
| 314 | \internal | - | ||||||||||||||||||||||||
| 315 | Duplicated from QtTest::toPrettyCString(). | - | ||||||||||||||||||||||||
| 316 | */ | - | ||||||||||||||||||||||||
| 317 | void QDebug::putByteArray(const char *begin, size_t length, Latin1Content content) | - | ||||||||||||||||||||||||
| 318 | { | - | ||||||||||||||||||||||||
| 319 | if (stream->testFlag(Stream::NoQuotes)) {
| 17-34 | ||||||||||||||||||||||||
| 320 | // no quotes, write the string directly too (no pretty-printing) | - | ||||||||||||||||||||||||
| 321 | // this respects the QTextStream state, though | - | ||||||||||||||||||||||||
| 322 | QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, int(length)) : QString::fromUtf8(begin, int(length));
| 5-29 | ||||||||||||||||||||||||
| 323 | stream->ts.d_ptr->putString(string); | - | ||||||||||||||||||||||||
| 324 | } else { executed 34 times by 4 tests: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 325 | // we'll reset the QTextStream formatting mechanisms, so save the state | - | ||||||||||||||||||||||||
| 326 | QDebugStateSaver saver(*this); | - | ||||||||||||||||||||||||
| 327 | stream->ts.d_ptr->params.reset(); | - | ||||||||||||||||||||||||
| 328 | putEscapedString(stream->ts.d_ptr.data(), reinterpret_cast<const uchar *>(begin), | - | ||||||||||||||||||||||||
| 329 | int(length), content == ContainsLatin1); | - | ||||||||||||||||||||||||
| 330 | } executed 17 times by 3 tests: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||
| 331 | } | - | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | /*! | - | ||||||||||||||||||||||||
| 334 | \fn QDebug::swap(QDebug &other) | - | ||||||||||||||||||||||||
| 335 | \since 5.0 | - | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | Swaps this debug stream instance with \a other. This function is | - | ||||||||||||||||||||||||
| 338 | very fast and never fails. | - | ||||||||||||||||||||||||
| 339 | */ | - | ||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||
| 341 | /*! | - | ||||||||||||||||||||||||
| 342 | Resets the stream formatting options, bringing it back to its original constructed state. | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | \sa space(), quote() | - | ||||||||||||||||||||||||
| 345 | \since 5.4 | - | ||||||||||||||||||||||||
| 346 | */ | - | ||||||||||||||||||||||||
| 347 | QDebug &QDebug::resetFormat() | - | ||||||||||||||||||||||||
| 348 | { | - | ||||||||||||||||||||||||
| 349 | stream->ts.reset(); | - | ||||||||||||||||||||||||
| 350 | stream->space = true; | - | ||||||||||||||||||||||||
| 351 | if (stream->context.version > 1)
| 0-921 | ||||||||||||||||||||||||
| 352 | stream->flags = 0; executed 921 times by 12 tests: stream->flags = 0;Executed by:
| 921 | ||||||||||||||||||||||||
| 353 | stream->setVerbosity(Stream::defaultVerbosity); | - | ||||||||||||||||||||||||
| 354 | return *this; executed 921 times by 12 tests: return *this;Executed by:
| 921 | ||||||||||||||||||||||||
| 355 | } | - | ||||||||||||||||||||||||
| 356 | - | |||||||||||||||||||||||||
| 357 | /*! | - | ||||||||||||||||||||||||
| 358 | \fn QDebug &QDebug::space() | - | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | Writes a space character to the debug stream and returns a reference to | - | ||||||||||||||||||||||||
| 361 | the stream. | - | ||||||||||||||||||||||||
| 362 | - | |||||||||||||||||||||||||
| 363 | The stream remembers that automatic insertion of spaces is | - | ||||||||||||||||||||||||
| 364 | enabled for future writes. | - | ||||||||||||||||||||||||
| 365 | - | |||||||||||||||||||||||||
| 366 | \sa nospace(), maybeSpace() | - | ||||||||||||||||||||||||
| 367 | */ | - | ||||||||||||||||||||||||
| 368 | - | |||||||||||||||||||||||||
| 369 | /*! | - | ||||||||||||||||||||||||
| 370 | \fn QDebug &QDebug::nospace() | - | ||||||||||||||||||||||||
| 371 | - | |||||||||||||||||||||||||
| 372 | Disables automatic insertion of spaces and returns a reference to the stream. | - | ||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||
| 374 | \sa space(), maybeSpace() | - | ||||||||||||||||||||||||
| 375 | */ | - | ||||||||||||||||||||||||
| 376 | - | |||||||||||||||||||||||||
| 377 | /*! | - | ||||||||||||||||||||||||
| 378 | \fn QDebug &QDebug::maybeSpace() | - | ||||||||||||||||||||||||
| 379 | - | |||||||||||||||||||||||||
| 380 | Writes a space character to the debug stream, depending on the current | - | ||||||||||||||||||||||||
| 381 | setting for automatic insertion of spaces, and returns a reference to the stream. | - | ||||||||||||||||||||||||
| 382 | - | |||||||||||||||||||||||||
| 383 | \sa space(), nospace() | - | ||||||||||||||||||||||||
| 384 | */ | - | ||||||||||||||||||||||||
| 385 | - | |||||||||||||||||||||||||
| 386 | /*! | - | ||||||||||||||||||||||||
| 387 | \fn bool QDebug::autoInsertSpaces() const | - | ||||||||||||||||||||||||
| 388 | - | |||||||||||||||||||||||||
| 389 | Returns \c true if this QDebug instance will automatically insert spaces | - | ||||||||||||||||||||||||
| 390 | between writes. | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | \since 5.0 | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | \sa QDebugStateSaver | - | ||||||||||||||||||||||||
| 395 | */ | - | ||||||||||||||||||||||||
| 396 | - | |||||||||||||||||||||||||
| 397 | /*! | - | ||||||||||||||||||||||||
| 398 | \fn void QDebug::setAutoInsertSpaces(bool b) | - | ||||||||||||||||||||||||
| 399 | - | |||||||||||||||||||||||||
| 400 | Enables automatic insertion of spaces between writes if \a b is true; otherwise | - | ||||||||||||||||||||||||
| 401 | automatic insertion of spaces is disabled. | - | ||||||||||||||||||||||||
| 402 | - | |||||||||||||||||||||||||
| 403 | \since 5.0 | - | ||||||||||||||||||||||||
| 404 | - | |||||||||||||||||||||||||
| 405 | \sa QDebugStateSaver | - | ||||||||||||||||||||||||
| 406 | */ | - | ||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | /*! | - | ||||||||||||||||||||||||
| 410 | \fn QDebug &QDebug::quote() | - | ||||||||||||||||||||||||
| 411 | \since 5.4 | - | ||||||||||||||||||||||||
| 412 | - | |||||||||||||||||||||||||
| 413 | Enables automatic insertion of quotation characters around QChar, QString and QByteArray | - | ||||||||||||||||||||||||
| 414 | contents and returns a reference to the stream. | - | ||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||
| 416 | Quoting is enabled by default. | - | ||||||||||||||||||||||||
| 417 | - | |||||||||||||||||||||||||
| 418 | \sa noquote(), maybeQuote() | - | ||||||||||||||||||||||||
| 419 | */ | - | ||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| 421 | /*! | - | ||||||||||||||||||||||||
| 422 | \fn QDebug &QDebug::noquote() | - | ||||||||||||||||||||||||
| 423 | \since 5.4 | - | ||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | Disables automatic insertion of quotation characters around QChar, QString and QByteArray | - | ||||||||||||||||||||||||
| 426 | contents and returns a reference to the stream. | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | When quoting is disabled, these types are printed without quotation | - | ||||||||||||||||||||||||
| 429 | characters and without escaping of non-printable characters. | - | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | \sa quote(), maybeQuote() | - | ||||||||||||||||||||||||
| 432 | */ | - | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | /*! | - | ||||||||||||||||||||||||
| 435 | \fn QDebug &QDebug::maybeQuote(char c) | - | ||||||||||||||||||||||||
| 436 | \since 5.4 | - | ||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | Writes a character \a c to the debug stream, depending on the | - | ||||||||||||||||||||||||
| 439 | current setting for automatic insertion of quotes, and returns a reference to the stream. | - | ||||||||||||||||||||||||
| 440 | - | |||||||||||||||||||||||||
| 441 | The default character is a double quote \c{"}. | - | ||||||||||||||||||||||||
| 442 | - | |||||||||||||||||||||||||
| 443 | \sa quote(), noquote() | - | ||||||||||||||||||||||||
| 444 | */ | - | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | /*! | - | ||||||||||||||||||||||||
| 447 | \fn int QDebug::verbosity() const | - | ||||||||||||||||||||||||
| 448 | \since 5.6 | - | ||||||||||||||||||||||||
| 449 | - | |||||||||||||||||||||||||
| 450 | Returns the verbosity of the debug stream. | - | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | Streaming operators can check the value to decide whether | - | ||||||||||||||||||||||||
| 453 | verbose output is desired and print more information depending on the | - | ||||||||||||||||||||||||
| 454 | level. Higher values indicate that more information is desired. | - | ||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | The allowed range is from 0 to 7. The default value is 2. | - | ||||||||||||||||||||||||
| 457 | - | |||||||||||||||||||||||||
| 458 | \sa setVerbosity() | - | ||||||||||||||||||||||||
| 459 | */ | - | ||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||
| 461 | /*! | - | ||||||||||||||||||||||||
| 462 | \fn void QDebug::setVerbosity(int verbosityLevel) | - | ||||||||||||||||||||||||
| 463 | \since 5.6 | - | ||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||
| 465 | Sets the verbosity of the stream to \a verbosityLevel. | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | The allowed range is from 0 to 7. The default value is 2. | - | ||||||||||||||||||||||||
| 468 | - | |||||||||||||||||||||||||
| 469 | \sa verbosity() | - | ||||||||||||||||||||||||
| 470 | */ | - | ||||||||||||||||||||||||
| 471 | - | |||||||||||||||||||||||||
| 472 | /*! | - | ||||||||||||||||||||||||
| 473 | \fn QDebug &QDebug::operator<<(QChar t) | - | ||||||||||||||||||||||||
| 474 | - | |||||||||||||||||||||||||
| 475 | Writes the character, \a t, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 476 | stream. Normally, QDebug prints control characters and non-US-ASCII | - | ||||||||||||||||||||||||
| 477 | characters as their C escape sequences or their Unicode value (\\u1234). To | - | ||||||||||||||||||||||||
| 478 | print non-printable characters without transformation, enable the noquote() | - | ||||||||||||||||||||||||
| 479 | functionality, but note that some QDebug backends may not be 8-bit clean | - | ||||||||||||||||||||||||
| 480 | and may not be able to represent \c t. | - | ||||||||||||||||||||||||
| 481 | */ | - | ||||||||||||||||||||||||
| 482 | - | |||||||||||||||||||||||||
| 483 | /*! | - | ||||||||||||||||||||||||
| 484 | \fn QDebug &QDebug::operator<<(bool t) | - | ||||||||||||||||||||||||
| 485 | - | |||||||||||||||||||||||||
| 486 | Writes the boolean value, \a t, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 487 | stream. | - | ||||||||||||||||||||||||
| 488 | */ | - | ||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||
| 490 | /*! | - | ||||||||||||||||||||||||
| 491 | \fn QDebug &QDebug::operator<<(char t) | - | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | Writes the character, \a t, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 494 | stream. | - | ||||||||||||||||||||||||
| 495 | */ | - | ||||||||||||||||||||||||
| 496 | - | |||||||||||||||||||||||||
| 497 | /*! | - | ||||||||||||||||||||||||
| 498 | \fn QDebug &QDebug::operator<<(signed short i) | - | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | Writes the signed short integer, \a i, to the stream and returns a reference | - | ||||||||||||||||||||||||
| 501 | to the stream. | - | ||||||||||||||||||||||||
| 502 | */ | - | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | /*! | - | ||||||||||||||||||||||||
| 505 | \fn QDebug &QDebug::operator<<(unsigned short i) | - | ||||||||||||||||||||||||
| 506 | - | |||||||||||||||||||||||||
| 507 | Writes then unsigned short integer, \a i, to the stream and returns a | - | ||||||||||||||||||||||||
| 508 | reference to the stream. | - | ||||||||||||||||||||||||
| 509 | */ | - | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | /*! | - | ||||||||||||||||||||||||
| 512 | \fn QDebug &QDebug::operator<<(signed int i) | - | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | Writes the signed integer, \a i, to the stream and returns a reference | - | ||||||||||||||||||||||||
| 515 | to the stream. | - | ||||||||||||||||||||||||
| 516 | */ | - | ||||||||||||||||||||||||
| 517 | - | |||||||||||||||||||||||||
| 518 | /*! | - | ||||||||||||||||||||||||
| 519 | \fn QDebug &QDebug::operator<<(unsigned int i) | - | ||||||||||||||||||||||||
| 520 | - | |||||||||||||||||||||||||
| 521 | Writes then unsigned integer, \a i, to the stream and returns a reference to | - | ||||||||||||||||||||||||
| 522 | the stream. | - | ||||||||||||||||||||||||
| 523 | */ | - | ||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||
| 525 | /*! | - | ||||||||||||||||||||||||
| 526 | \fn QDebug &QDebug::operator<<(signed long l) | - | ||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||
| 528 | Writes the signed long integer, \a l, to the stream and returns a reference | - | ||||||||||||||||||||||||
| 529 | to the stream. | - | ||||||||||||||||||||||||
| 530 | */ | - | ||||||||||||||||||||||||
| 531 | - | |||||||||||||||||||||||||
| 532 | /*! | - | ||||||||||||||||||||||||
| 533 | \fn QDebug &QDebug::operator<<(unsigned long l) | - | ||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||
| 535 | Writes then unsigned long integer, \a l, to the stream and returns a reference | - | ||||||||||||||||||||||||
| 536 | to the stream. | - | ||||||||||||||||||||||||
| 537 | */ | - | ||||||||||||||||||||||||
| 538 | - | |||||||||||||||||||||||||
| 539 | /*! | - | ||||||||||||||||||||||||
| 540 | \fn QDebug &QDebug::operator<<(qint64 i) | - | ||||||||||||||||||||||||
| 541 | - | |||||||||||||||||||||||||
| 542 | Writes the signed 64-bit integer, \a i, to the stream and returns a reference | - | ||||||||||||||||||||||||
| 543 | to the stream. | - | ||||||||||||||||||||||||
| 544 | */ | - | ||||||||||||||||||||||||
| 545 | - | |||||||||||||||||||||||||
| 546 | /*! | - | ||||||||||||||||||||||||
| 547 | \fn QDebug &QDebug::operator<<(quint64 i) | - | ||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||
| 549 | Writes then unsigned 64-bit integer, \a i, to the stream and returns a | - | ||||||||||||||||||||||||
| 550 | reference to the stream. | - | ||||||||||||||||||||||||
| 551 | */ | - | ||||||||||||||||||||||||
| 552 | - | |||||||||||||||||||||||||
| 553 | /*! | - | ||||||||||||||||||||||||
| 554 | \fn QDebug &QDebug::operator<<(float f) | - | ||||||||||||||||||||||||
| 555 | - | |||||||||||||||||||||||||
| 556 | Writes the 32-bit floating point number, \a f, to the stream and returns a | - | ||||||||||||||||||||||||
| 557 | reference to the stream. | - | ||||||||||||||||||||||||
| 558 | */ | - | ||||||||||||||||||||||||
| 559 | - | |||||||||||||||||||||||||
| 560 | /*! | - | ||||||||||||||||||||||||
| 561 | \fn QDebug &QDebug::operator<<(double f) | - | ||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||
| 563 | Writes the 64-bit floating point number, \a f, to the stream and returns a | - | ||||||||||||||||||||||||
| 564 | reference to the stream. | - | ||||||||||||||||||||||||
| 565 | */ | - | ||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||
| 567 | /*! | - | ||||||||||||||||||||||||
| 568 | \fn QDebug &QDebug::operator<<(const char *s) | - | ||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | Writes the '\\0'-terminated string, \a s, to the stream and returns a | - | ||||||||||||||||||||||||
| 571 | reference to the stream. The string is never quoted nor transformed to the | - | ||||||||||||||||||||||||
| 572 | output, but note that some QDebug backends might not be 8-bit clean. | - | ||||||||||||||||||||||||
| 573 | */ | - | ||||||||||||||||||||||||
| 574 | - | |||||||||||||||||||||||||
| 575 | /*! | - | ||||||||||||||||||||||||
| 576 | \fn QDebug &QDebug::operator<<(const QString &s) | - | ||||||||||||||||||||||||
| 577 | - | |||||||||||||||||||||||||
| 578 | Writes the string, \a s, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 579 | stream. Normally, QDebug prints the string inside quotes and transforms | - | ||||||||||||||||||||||||
| 580 | non-printable characters to their Unicode values (\\u1234). | - | ||||||||||||||||||||||||
| 581 | - | |||||||||||||||||||||||||
| 582 | To print non-printable characters without transformation, enable the | - | ||||||||||||||||||||||||
| 583 | noquote() functionality. Note that some QDebug backends might not be 8-bit | - | ||||||||||||||||||||||||
| 584 | clean. | - | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | Output examples: | - | ||||||||||||||||||||||||
| 587 | \code | - | ||||||||||||||||||||||||
| 588 | QString s; | - | ||||||||||||||||||||||||
| 589 | - | |||||||||||||||||||||||||
| 590 | s = "a"; | - | ||||||||||||||||||||||||
| 591 | qDebug().noquote() << s; // prints: a | - | ||||||||||||||||||||||||
| 592 | qDebug() << s; // prints: "a" | - | ||||||||||||||||||||||||
| 593 | - | |||||||||||||||||||||||||
| 594 | s = "\"a\r\n\""; | - | ||||||||||||||||||||||||
| 595 | qDebug() << s; // prints: "\"a\r\n\"" | - | ||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | s = "\033"; // escape character | - | ||||||||||||||||||||||||
| 598 | qDebug() << s; // prints: "\u001B" | - | ||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||
| 600 | s = "\u00AD"; // SOFT HYPHEN | - | ||||||||||||||||||||||||
| 601 | qDebug() << s; // prints: "\u00AD" | - | ||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||
| 603 | s = "\u00E1"; // LATIN SMALL LETTER A WITH ACUTE | - | ||||||||||||||||||||||||
| 604 | qDebug() << s; // prints: "á" | - | ||||||||||||||||||||||||
| 605 | - | |||||||||||||||||||||||||
| 606 | s = "a\u0301"; // "a" followed by COMBINING ACUTE ACCENT | - | ||||||||||||||||||||||||
| 607 | qDebug() << s; // prints: "á"; | - | ||||||||||||||||||||||||
| 608 | - | |||||||||||||||||||||||||
| 609 | s = "\u0430\u0301"; // CYRILLIC SMALL LETTER A followed by COMBINING ACUTE ACCENT | - | ||||||||||||||||||||||||
| 610 | qDebug() << s; // prints: "а́" | - | ||||||||||||||||||||||||
| 611 | \endcode | - | ||||||||||||||||||||||||
| 612 | */ | - | ||||||||||||||||||||||||
| 613 | - | |||||||||||||||||||||||||
| 614 | /*! | - | ||||||||||||||||||||||||
| 615 | \fn QDebug &QDebug::operator<<(const QStringRef &s) | - | ||||||||||||||||||||||||
| 616 | - | |||||||||||||||||||||||||
| 617 | Writes the string, \a s, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 618 | stream. Normally, QDebug prints the string inside quotes and transforms | - | ||||||||||||||||||||||||
| 619 | non-printable characters to their Unicode values (\\u1234). | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | To print non-printable characters without transformation, enable the | - | ||||||||||||||||||||||||
| 622 | noquote() functionality. Note that some QDebug backends might not be 8-bit | - | ||||||||||||||||||||||||
| 623 | clean. | - | ||||||||||||||||||||||||
| 624 | - | |||||||||||||||||||||||||
| 625 | See the QString overload for examples. | - | ||||||||||||||||||||||||
| 626 | */ | - | ||||||||||||||||||||||||
| 627 | - | |||||||||||||||||||||||||
| 628 | /*! | - | ||||||||||||||||||||||||
| 629 | \fn QDebug &QDebug::operator<<(QLatin1String s) | - | ||||||||||||||||||||||||
| 630 | - | |||||||||||||||||||||||||
| 631 | Writes the string, \a s, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 632 | stream. Normally, QDebug prints the string inside quotes and transforms | - | ||||||||||||||||||||||||
| 633 | non-printable characters to their Unicode values (\\u1234). | - | ||||||||||||||||||||||||
| 634 | - | |||||||||||||||||||||||||
| 635 | To print non-printable characters without transformation, enable the | - | ||||||||||||||||||||||||
| 636 | noquote() functionality. Note that some QDebug backends might not be 8-bit | - | ||||||||||||||||||||||||
| 637 | clean. | - | ||||||||||||||||||||||||
| 638 | - | |||||||||||||||||||||||||
| 639 | See the QString overload for examples. | - | ||||||||||||||||||||||||
| 640 | */ | - | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | /*! | - | ||||||||||||||||||||||||
| 643 | \fn QDebug &QDebug::operator<<(const QByteArray &b) | - | ||||||||||||||||||||||||
| 644 | - | |||||||||||||||||||||||||
| 645 | Writes the byte array, \a b, to the stream and returns a reference to the | - | ||||||||||||||||||||||||
| 646 | stream. Normally, QDebug prints the array inside quotes and transforms | - | ||||||||||||||||||||||||
| 647 | control or non-US-ASCII characters to their C escape sequences (\\xAB). This | - | ||||||||||||||||||||||||
| 648 | way, the output is always 7-bit clean and the string can be copied from the | - | ||||||||||||||||||||||||
| 649 | output and pasted back into C++ sources, if necessary. | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | To print non-printable characters without transformation, enable the | - | ||||||||||||||||||||||||
| 652 | noquote() functionality. Note that some QDebug backends might not be 8-bit | - | ||||||||||||||||||||||||
| 653 | clean. | - | ||||||||||||||||||||||||
| 654 | - | |||||||||||||||||||||||||
| 655 | Output examples: | - | ||||||||||||||||||||||||
| 656 | \code | - | ||||||||||||||||||||||||
| 657 | QByteArray ba; | - | ||||||||||||||||||||||||
| 658 | - | |||||||||||||||||||||||||
| 659 | ba = "a"; | - | ||||||||||||||||||||||||
| 660 | qDebug().noquote() << ba; // prints: a | - | ||||||||||||||||||||||||
| 661 | qDebug() << ba; // prints: "a" | - | ||||||||||||||||||||||||
| 662 | - | |||||||||||||||||||||||||
| 663 | ba = "\"a\r\n\""; | - | ||||||||||||||||||||||||
| 664 | qDebug() << ba; // prints: "\"a\r\n\"" | - | ||||||||||||||||||||||||
| 665 | - | |||||||||||||||||||||||||
| 666 | ba = "\033"; // escape character | - | ||||||||||||||||||||||||
| 667 | qDebug() << ba; // prints: "\x1B" | - | ||||||||||||||||||||||||
| 668 | - | |||||||||||||||||||||||||
| 669 | ba = "\xC3\xA1"; | - | ||||||||||||||||||||||||
| 670 | qDebug() << ba; // prints: "\xC3\xA1" | - | ||||||||||||||||||||||||
| 671 | - | |||||||||||||||||||||||||
| 672 | ba = QByteArray("a\0b", 3); | - | ||||||||||||||||||||||||
| 673 | qDebug() << ba // prints: "\a\x00""b" | - | ||||||||||||||||||||||||
| 674 | \endcode | - | ||||||||||||||||||||||||
| 675 | - | |||||||||||||||||||||||||
| 676 | Note how QDebug needed to close and reopen the string in the way C and C++ | - | ||||||||||||||||||||||||
| 677 | languages concatenate string literals so that the letter 'b' is not | - | ||||||||||||||||||||||||
| 678 | interpreted as part of the previous hexadecimal escape sequence. | - | ||||||||||||||||||||||||
| 679 | */ | - | ||||||||||||||||||||||||
| 680 | - | |||||||||||||||||||||||||
| 681 | /*! | - | ||||||||||||||||||||||||
| 682 | \fn QDebug &QDebug::operator<<(const void *p) | - | ||||||||||||||||||||||||
| 683 | - | |||||||||||||||||||||||||
| 684 | Writes a pointer, \a p, to the stream and returns a reference to the stream. | - | ||||||||||||||||||||||||
| 685 | */ | - | ||||||||||||||||||||||||
| 686 | - | |||||||||||||||||||||||||
| 687 | /*! | - | ||||||||||||||||||||||||
| 688 | \fn QDebug &QDebug::operator<<(QTextStreamFunction f) | - | ||||||||||||||||||||||||
| 689 | \internal | - | ||||||||||||||||||||||||
| 690 | */ | - | ||||||||||||||||||||||||
| 691 | - | |||||||||||||||||||||||||
| 692 | /*! | - | ||||||||||||||||||||||||
| 693 | \fn QDebug &QDebug::operator<<(QTextStreamManipulator m) | - | ||||||||||||||||||||||||
| 694 | \internal | - | ||||||||||||||||||||||||
| 695 | */ | - | ||||||||||||||||||||||||
| 696 | - | |||||||||||||||||||||||||
| 697 | /*! | - | ||||||||||||||||||||||||
| 698 | \fn QDebug operator<<(QDebug stream, const QList<T> &list) | - | ||||||||||||||||||||||||
| 699 | \relates QDebug | - | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | Writes the contents of \a list to \a stream. \c T needs to | - | ||||||||||||||||||||||||
| 702 | support streaming into QDebug. | - | ||||||||||||||||||||||||
| 703 | */ | - | ||||||||||||||||||||||||
| 704 | - | |||||||||||||||||||||||||
| 705 | /*! | - | ||||||||||||||||||||||||
| 706 | \fn QDebug operator<<(QDebug stream, const QVector<T> &vector) | - | ||||||||||||||||||||||||
| 707 | \relates QDebug | - | ||||||||||||||||||||||||
| 708 | - | |||||||||||||||||||||||||
| 709 | Writes the contents of \a vector to \a stream. \c T needs to | - | ||||||||||||||||||||||||
| 710 | support streaming into QDebug. | - | ||||||||||||||||||||||||
| 711 | */ | - | ||||||||||||||||||||||||
| 712 | - | |||||||||||||||||||||||||
| 713 | /*! | - | ||||||||||||||||||||||||
| 714 | \fn QDebug operator<<(QDebug stream, const QSet<T> &set) | - | ||||||||||||||||||||||||
| 715 | \relates QDebug | - | ||||||||||||||||||||||||
| 716 | - | |||||||||||||||||||||||||
| 717 | Writes the contents of \a set to \a stream. \c T needs to | - | ||||||||||||||||||||||||
| 718 | support streaming into QDebug. | - | ||||||||||||||||||||||||
| 719 | */ | - | ||||||||||||||||||||||||
| 720 | - | |||||||||||||||||||||||||
| 721 | /*! | - | ||||||||||||||||||||||||
| 722 | \fn QDebug operator<<(QDebug stream, const QMap<Key, T> &map) | - | ||||||||||||||||||||||||
| 723 | \relates QDebug | - | ||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||
| 725 | Writes the contents of \a map to \a stream. Both \c Key and | - | ||||||||||||||||||||||||
| 726 | \c T need to support streaming into QDebug. | - | ||||||||||||||||||||||||
| 727 | */ | - | ||||||||||||||||||||||||
| 728 | - | |||||||||||||||||||||||||
| 729 | /*! | - | ||||||||||||||||||||||||
| 730 | \fn QDebug operator<<(QDebug stream, const QHash<Key, T> &hash) | - | ||||||||||||||||||||||||
| 731 | \relates QDebug | - | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | Writes the contents of \a hash to \a stream. Both \c Key and | - | ||||||||||||||||||||||||
| 734 | \c T need to support streaming into QDebug. | - | ||||||||||||||||||||||||
| 735 | */ | - | ||||||||||||||||||||||||
| 736 | - | |||||||||||||||||||||||||
| 737 | /*! | - | ||||||||||||||||||||||||
| 738 | \fn QDebug operator<<(QDebug stream, const QPair<T1, T2> &pair) | - | ||||||||||||||||||||||||
| 739 | \relates QDebug | - | ||||||||||||||||||||||||
| 740 | - | |||||||||||||||||||||||||
| 741 | Writes the contents of \a pair to \a stream. Both \c T1 and | - | ||||||||||||||||||||||||
| 742 | \c T2 need to support streaming into QDebug. | - | ||||||||||||||||||||||||
| 743 | */ | - | ||||||||||||||||||||||||
| 744 | - | |||||||||||||||||||||||||
| 745 | /*! | - | ||||||||||||||||||||||||
| 746 | \fn QDebug operator<<(QDebug stream, const QFlags<T> &flag) | - | ||||||||||||||||||||||||
| 747 | \relates QDebug | - | ||||||||||||||||||||||||
| 748 | \since 4.7 | - | ||||||||||||||||||||||||
| 749 | - | |||||||||||||||||||||||||
| 750 | Writes \a flag to \a stream. | - | ||||||||||||||||||||||||
| 751 | */ | - | ||||||||||||||||||||||||
| 752 | - | |||||||||||||||||||||||||
| 753 | /*! | - | ||||||||||||||||||||||||
| 754 | \class QDebugStateSaver | - | ||||||||||||||||||||||||
| 755 | \inmodule QtCore | - | ||||||||||||||||||||||||
| 756 | \brief Convenience class for custom QDebug operators | - | ||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||
| 758 | Saves the settings used by QDebug, and restores them upon destruction, | - | ||||||||||||||||||||||||
| 759 | then calls \l {QDebug::maybeSpace()}{maybeSpace()}, to separate arguments with a space if | - | ||||||||||||||||||||||||
| 760 | \l {QDebug::autoInsertSpaces()}{autoInsertSpaces()} was true at the time of constructing the QDebugStateSaver. | - | ||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||
| 762 | The automatic insertion of spaces between writes is one of the settings | - | ||||||||||||||||||||||||
| 763 | that QDebugStateSaver stores for the duration of the current block. | - | ||||||||||||||||||||||||
| 764 | - | |||||||||||||||||||||||||
| 765 | The settings of the internal QTextStream are also saved and restored, | - | ||||||||||||||||||||||||
| 766 | so that using << hex in a QDebug operator doesn't affect other QDebug | - | ||||||||||||||||||||||||
| 767 | operators. | - | ||||||||||||||||||||||||
| 768 | - | |||||||||||||||||||||||||
| 769 | \since 5.1 | - | ||||||||||||||||||||||||
| 770 | */ | - | ||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||
| 772 | class QDebugStateSaverPrivate | - | ||||||||||||||||||||||||
| 773 | { | - | ||||||||||||||||||||||||
| 774 | public: | - | ||||||||||||||||||||||||
| 775 | QDebugStateSaverPrivate(QDebug &dbg) | - | ||||||||||||||||||||||||
| 776 | : m_dbg(dbg), | - | ||||||||||||||||||||||||
| 777 | m_spaces(dbg.autoInsertSpaces()), | - | ||||||||||||||||||||||||
| 778 | m_flags(0), | - | ||||||||||||||||||||||||
| 779 | m_streamParams(dbg.stream->ts.d_ptr->params) | - | ||||||||||||||||||||||||
| 780 | { | - | ||||||||||||||||||||||||
| 781 | if (m_dbg.stream->context.version > 1)
| 0-14887 | ||||||||||||||||||||||||
| 782 | m_flags = m_dbg.stream->flags; executed 14887 times by 49 tests: m_flags = m_dbg.stream->flags;Executed by:
| 14887 | ||||||||||||||||||||||||
| 783 | } executed 14887 times by 49 tests: end of blockExecuted by:
| 14887 | ||||||||||||||||||||||||
| 784 | void restoreState() | - | ||||||||||||||||||||||||
| 785 | { | - | ||||||||||||||||||||||||
| 786 | const bool currentSpaces = m_dbg.autoInsertSpaces(); | - | ||||||||||||||||||||||||
| 787 | if (currentSpaces && !m_spaces)
| 1-12826 | ||||||||||||||||||||||||
| 788 | if (m_dbg.stream->buffer.endsWith(QLatin1Char(' ')))
| 0-1 | ||||||||||||||||||||||||
| 789 | m_dbg.stream->buffer.chop(1); executed 1 time by 1 test: m_dbg.stream->buffer.chop(1);Executed by:
| 1 | ||||||||||||||||||||||||
| 790 | - | |||||||||||||||||||||||||
| 791 | m_dbg.setAutoInsertSpaces(m_spaces); | - | ||||||||||||||||||||||||
| 792 | m_dbg.stream->ts.d_ptr->params = m_streamParams; | - | ||||||||||||||||||||||||
| 793 | if (m_dbg.stream->context.version > 1)
| 0-14887 | ||||||||||||||||||||||||
| 794 | m_dbg.stream->flags = m_flags; executed 14887 times by 49 tests: m_dbg.stream->flags = m_flags;Executed by:
| 14887 | ||||||||||||||||||||||||
| 795 | - | |||||||||||||||||||||||||
| 796 | if (!currentSpaces && m_spaces)
| 519-12826 | ||||||||||||||||||||||||
| 797 | m_dbg.stream->ts << ' '; executed 519 times by 24 tests: m_dbg.stream->ts << ' ';Executed by:
| 519 | ||||||||||||||||||||||||
| 798 | } executed 14887 times by 49 tests: end of blockExecuted by:
| 14887 | ||||||||||||||||||||||||
| 799 | - | |||||||||||||||||||||||||
| 800 | QDebug &m_dbg; | - | ||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||
| 802 | // QDebug state | - | ||||||||||||||||||||||||
| 803 | const bool m_spaces; | - | ||||||||||||||||||||||||
| 804 | int m_flags; | - | ||||||||||||||||||||||||
| 805 | - | |||||||||||||||||||||||||
| 806 | // QTextStream state | - | ||||||||||||||||||||||||
| 807 | const QTextStreamPrivate::Params m_streamParams; | - | ||||||||||||||||||||||||
| 808 | }; | - | ||||||||||||||||||||||||
| 809 | - | |||||||||||||||||||||||||
| 810 | - | |||||||||||||||||||||||||
| 811 | /*! | - | ||||||||||||||||||||||||
| 812 | Creates a QDebugStateSaver instance, which saves the settings | - | ||||||||||||||||||||||||
| 813 | currently used by \a dbg. | - | ||||||||||||||||||||||||
| 814 | - | |||||||||||||||||||||||||
| 815 | \sa QDebug::setAutoInsertSpaces(), QDebug::autoInsertSpaces() | - | ||||||||||||||||||||||||
| 816 | */ | - | ||||||||||||||||||||||||
| 817 | QDebugStateSaver::QDebugStateSaver(QDebug &dbg) | - | ||||||||||||||||||||||||
| 818 | : d(new QDebugStateSaverPrivate(dbg)) | - | ||||||||||||||||||||||||
| 819 | { | - | ||||||||||||||||||||||||
| 820 | } executed 14887 times by 49 tests: end of blockExecuted by:
| 14887 | ||||||||||||||||||||||||
| 821 | - | |||||||||||||||||||||||||
| 822 | /*! | - | ||||||||||||||||||||||||
| 823 | Destroys a QDebugStateSaver instance, which restores the settings | - | ||||||||||||||||||||||||
| 824 | used when the QDebugStateSaver instance was created. | - | ||||||||||||||||||||||||
| 825 | - | |||||||||||||||||||||||||
| 826 | \sa QDebug::setAutoInsertSpaces(), QDebug::autoInsertSpaces() | - | ||||||||||||||||||||||||
| 827 | */ | - | ||||||||||||||||||||||||
| 828 | QDebugStateSaver::~QDebugStateSaver() | - | ||||||||||||||||||||||||
| 829 | { | - | ||||||||||||||||||||||||
| 830 | d->restoreState(); | - | ||||||||||||||||||||||||
| 831 | } executed 14887 times by 49 tests: end of blockExecuted by:
| 14887 | ||||||||||||||||||||||||
| 832 | - | |||||||||||||||||||||||||
| 833 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 834 | /*! | - | ||||||||||||||||||||||||
| 835 | \internal | - | ||||||||||||||||||||||||
| 836 | */ | - | ||||||||||||||||||||||||
| 837 | QDebug qt_QMetaEnum_debugOperator(QDebug &dbg, int value, const QMetaObject *meta, const char *name) | - | ||||||||||||||||||||||||
| 838 | { | - | ||||||||||||||||||||||||
| 839 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||||||||
| 840 | QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name)); | - | ||||||||||||||||||||||||
| 841 | const char *key = me.valueToKey(value); | - | ||||||||||||||||||||||||
| 842 | dbg.nospace() << meta->className() << "::" << name << '('; | - | ||||||||||||||||||||||||
| 843 | if (key)
| 20-183 | ||||||||||||||||||||||||
| 844 | dbg << key; executed 183 times by 9 tests: dbg << key;Executed by:
| 183 | ||||||||||||||||||||||||
| 845 | else | - | ||||||||||||||||||||||||
| 846 | dbg << value; executed 20 times by 1 test: dbg << value;Executed by:
| 20 | ||||||||||||||||||||||||
| 847 | dbg << ')'; | - | ||||||||||||||||||||||||
| 848 | return dbg; executed 203 times by 9 tests: return dbg;Executed by:
| 203 | ||||||||||||||||||||||||
| 849 | } | - | ||||||||||||||||||||||||
| 850 | - | |||||||||||||||||||||||||
| 851 | QDebug qt_QMetaEnum_flagDebugOperator(QDebug &debug, quint64 value, const QMetaObject *meta, const char *name) | - | ||||||||||||||||||||||||
| 852 | { | - | ||||||||||||||||||||||||
| 853 | QDebugStateSaver saver(debug); | - | ||||||||||||||||||||||||
| 854 | debug.resetFormat(); | - | ||||||||||||||||||||||||
| 855 | debug.noquote(); | - | ||||||||||||||||||||||||
| 856 | debug.nospace(); | - | ||||||||||||||||||||||||
| 857 | debug << "QFlags<"; | - | ||||||||||||||||||||||||
| 858 | const QMetaEnum me = meta->enumerator(meta->indexOfEnumerator(name)); | - | ||||||||||||||||||||||||
| 859 | if (const char *scope = me.scope())
| 0-23 | ||||||||||||||||||||||||
| 860 | debug << scope << "::"; executed 23 times by 2 tests: debug << scope << "::";Executed by:
| 23 | ||||||||||||||||||||||||
| 861 | debug << me.name() << ">(" << me.valueToKeys(value) << ')'; | - | ||||||||||||||||||||||||
| 862 | return debug; executed 23 times by 2 tests: return debug;Executed by:
| 23 | ||||||||||||||||||||||||
| 863 | } | - | ||||||||||||||||||||||||
| 864 | #endif // !QT_NO_QOBJECT | - | ||||||||||||||||||||||||
| 865 | - | |||||||||||||||||||||||||
| 866 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |