source: trunk/src/corelib/io/qdebug.cpp@ 494

Last change on this file since 494 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.4 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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/*!