QDebug 类为调试信息提供输出流。 更多...
头: | #include <QDebug> |
qmake: | QT += core |
enum | VerbosityLevel { MinimumVerbosity, DefaultVerbosity, MaximumVerbosity } |
QDebug (const QDebug & o ) | |
QDebug (QtMsgType t ) | |
QDebug (QString * string ) | |
QDebug (QIODevice * device ) | |
QDebug & | operator= (const QDebug & other ) |
~QDebug () | |
bool | autoInsertSpaces () const |
QDebug & | maybeQuote (char c = '"') |
QDebug & | maybeSpace () |
QDebug & | noquote () |
QDebug & | nospace () |
QDebug & | quote () |
QDebug & | resetFormat () |
void | setAutoInsertSpaces (bool b ) |
void | setVerbosity (int verbosityLevel ) |
QDebug & | space () |
void | swap (QDebug & other ) |
QDebug & | verbosity (int verbosityLevel ) |
int | verbosity () const |
QDebug & | operator<< (QChar t ) |
QDebug & | operator<< (bool t ) |
QDebug & | operator<< (char t ) |
QDebug & | operator<< (short t ) |
QDebug & | operator<< (unsigned short t ) |
QDebug & | operator<< (char16_t t ) |
QDebug & | operator<< (char32_t t ) |
QDebug & | operator<< (int t ) |
QDebug & | operator<< (unsigned int t ) |
QDebug & | operator<< (long t ) |
QDebug & | operator<< (unsigned long t ) |
QDebug & | operator<< (qint64 t ) |
QDebug & | operator<< (quint64 t ) |
QDebug & | operator<< (float t ) |
QDebug & | operator<< (double t ) |
QDebug & | operator<< (const char * t ) |
QDebug & | operator<< (const QString & t ) |
QDebug & | operator<< (const QStringRef & t ) |
QDebug & | operator<< (QStringView s ) |
QDebug & | operator<< (QLatin1String t ) |
QDebug & | operator<< (const QByteArray & t ) |
QDebug & | operator<< (const void * t ) |
QDebug | operator<< (QDebug debug , const QFlags<T> & flags ) |
QDebug | operator<< (QDebug debug , const QList<T> & list ) |
QDebug | operator<< (QDebug debug , const QVector<T> & vec ) |
QDebug | operator<< (QDebug debug , const std::vector<T, Alloc> & vec ) |
QDebug | operator<< (QDebug debug , const std::list<T, Alloc> & vec ) |
QDebug | operator<< (QDebug debug , const std::map<Key, T, Compare, Alloc> & map ) |
QDebug | operator<< (QDebug debug , const std::multimap<Key, T, Compare, Alloc> & map ) |
QDebug | operator<< (QDebug debug , const QMap<Key, T> & map ) |
QDebug | operator<< (QDebug debug , const QHash<Key, T> & hash ) |
QDebug | operator<< (QDebug debug , const QPair<T1, T2> & pair ) |
QDebug | operator<< (QDebug debug , const QSet<T> & set ) |
就会使用 QDebug,每当开发者需要把调试 (或跟踪) 信息写入输出到设备、文件、字符串或控制台时。
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 。同样, qWarning (), qCritical () 和 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 或任何其它 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.
QDebug formats output so that it's easily readable. It automatically adds spaces between arguments, and adds quotes around QString , QByteArray , QChar 自变量。
可以微调这些选项透过 space (), nospace () 和 quote (), noquote () 方法。此外, QTextStream 操作符 可以管道到 QDebug 流。
QDebugStateSaver limits changes to the formatting to the current scope. resetFormat () resets the options to the default ones.
Many standard types can be written to QDebug objects, and Qt provides support for most Qt value types. To add support for custom types, you need to implement a streaming operator, as in the following example:
QDebug operator<<(QDebug debug, const Coordinate &c) { QDebugStateSaver saver(debug); debug.nospace() << '(' << c.x() << ", " << c.y() << ')'; return debug; }
This is described in the 调试技术 and 创建自定义 Qt 类型 documents.
此枚举描述冗余级别的范围。
常量 | 值 |
---|---|
QDebug::MinimumVerbosity
|
0
|
QDebug::DefaultVerbosity
|
2
|
QDebug::MaximumVerbosity
|
7
|
该枚举在 Qt 5.13 引入或被修改。
另请参阅 verbosity () 和 setVerbosity ().
Constructs a copy of the other debug stream o .
Constructs a debug stream that writes to the handler for the message type t .
Constructs a debug stream that writes to the given string .
Constructs a debug stream that writes to the given device .
赋值 other debug stream to this stream and returns a reference to this stream.
Flushes any pending data to be written and destroys the debug stream.
返回
true
若此
QDebug
instance will automatically insert spaces between writes.
该函数在 Qt 5.0 引入。
另请参阅 setAutoInsertSpaces () 和 QDebugStateSaver .
Writes a character c to the debug stream, depending on the current setting for automatic insertion of quotes, and returns a reference to the stream.
默认字符是双引号
"
.
该函数在 Qt 5.4 引入。
Writes a space character to the debug stream, depending on the current setting for automatic insertion of spaces, and returns a reference to the stream.
Disables automatic insertion of quotation characters around QChar , QString and QByteArray contents and returns a reference to the stream.
When quoting is disabled, these types are printed without quotation characters and without escaping of non-printable characters.
该函数在 Qt 5.4 引入。
另请参阅 quote () 和 maybeQuote ().
Disables automatic insertion of spaces and returns a reference to the stream.
另请参阅 space () 和 maybeSpace ().
Enables automatic insertion of quotation characters around QChar , QString and QByteArray contents and returns a reference to the stream.
Quoting is enabled by default.
该函数在 Qt 5.4 引入。
另请参阅 noquote () 和 maybeQuote ().
Resets the stream formatting options, bringing it back to its original constructed state.
该函数在 Qt 5.4 引入。
Enables automatic insertion of spaces between writes if b is true; otherwise automatic insertion of spaces is disabled.
该函数在 Qt 5.0 引入。
另请参阅 autoInsertSpaces () 和 QDebugStateSaver .
Sets the verbosity of the stream to verbosityLevel .
允许范围是从 0 到 7。默认值为 2。
该函数在 Qt 5.6 引入。
另请参阅 verbosity () 和 VerbosityLevel .
Writes a space character to the debug stream and returns a reference to the stream.
The stream remembers that automatic insertion of spaces is enabled for future writes.
另请参阅 nospace () 和 maybeSpace ().
Swaps this debug stream instance with other 。此函数非常快且从不失败。
该函数在 Qt 5.0 引入。
Sets the verbosity of the stream to verbosityLevel 并返回流引用。
允许范围是从 0 到 7。默认值为 2。
该函数在 Qt 5.13 引入。
另请参阅 verbosity (), setVerbosity (),和 VerbosityLevel .
返回调试流的冗余。
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.
允许范围是从 0 到 7。默认值为 2。
该函数在 Qt 5.6 引入。
另请参阅 setVerbosity () 和 VerbosityLevel .
Writes the character,
t
, to the stream and returns a reference to the stream. Normally,
QDebug
prints control characters and non-US-ASCII characters as their C escape sequences or their Unicode value (\u1234). To print non-printable characters without transformation, enable the
noquote
() functionality, but note that some
QDebug
backends may not be 8-bit clean and may not be able to represent
t
.
Writes the boolean value, t , to the stream and returns a reference to the stream.
Writes the character, t , to the stream and returns a reference to the stream.
Writes the signed short integer, t , to the stream and returns a reference to the stream.
Writes then unsigned short integer, t , to the stream and returns a reference to the stream.
Writes the UTF-16 character, t , to the stream and returns a reference to the stream.
该函数在 Qt 5.5 引入。
Writes the UTF-32 character, t , to the stream and returns a reference to the stream.
该函数在 Qt 5.5 引入。
Writes the signed integer, t , to the stream and returns a reference to the stream.
Writes then unsigned integer, t , to the stream and returns a reference to the stream.
Writes the signed long integer, t , to the stream and returns a reference to the stream.
Writes then unsigned long integer, t , to the stream and returns a reference to the stream.
Writes the signed 64-bit integer, t , to the stream and returns a reference to the stream.
Writes then unsigned 64-bit integer, t , to the stream and returns a reference to the stream.
Writes the 32-bit floating point number, t , to the stream and returns a reference to the stream.
Writes the 64-bit floating point number, t , to the stream and returns a reference to the stream.
Writes the '\0'-terminated string, t , to the stream and returns a reference to the stream. The string is never quoted nor transformed to the output, but note that some QDebug backends might not be 8-bit clean.
写入字符串 t , to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the noquote () functionality. Note that some QDebug backends might not be 8-bit clean.
输出范例:
QString s; s = "a"; qDebug().noquote() << s; // prints: a qDebug() << s; // prints: "a" s = "\"a\r\n\""; qDebug() << s; // prints: "\"a\r\n\"" s = "\033"; // escape character qDebug() << s; // prints: "\u001B" s = "\u00AD"; // SOFT HYPHEN qDebug() << s; // prints: "\u00AD" s = "\u00E1"; // LATIN SMALL LETTER A WITH ACUTE qDebug() << s; // prints: "á" s = "a\u0301"; // "a" followed by COMBINING ACUTE ACCENT qDebug() << s; // prints: "á"; s = "\u0430\u0301"; // CYRILLIC SMALL LETTER A followed by COMBINING ACUTE ACCENT qDebug() << s; // prints: "а́"
写入字符串 t , to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the noquote () functionality. Note that some QDebug backends might not be 8-bit clean.
见 QString overload for examples.
Writes the string view, s , to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the noquote () functionality. Note that some QDebug backends might not be 8-bit clean.
见 QString overload for examples.
该函数在 Qt 5.10 引入。
写入字符串 t , to the stream and returns a reference to the stream. Normally, QDebug prints the string inside quotes and transforms non-printable characters to their Unicode values (\u1234).
To print non-printable characters without transformation, enable the noquote () functionality. Note that some QDebug backends might not be 8-bit clean.
见 QString overload for examples.
Writes the byte array, t , to the stream and returns a reference to the stream. Normally, QDebug prints the array inside quotes and transforms control or non-US-ASCII characters to their C escape sequences (\xAB). This way, the output is always 7-bit clean and the string can be copied from the output and pasted back into C++ sources, if necessary.
To print non-printable characters without transformation, enable the noquote () functionality. Note that some QDebug backends might not be 8-bit clean.
输出范例:
QByteArray ba; ba = "a"; qDebug().noquote() << ba; // prints: a qDebug() << ba; // prints: "a" ba = "\"a\r\n\""; qDebug() << ba; // prints: "\"a\r\n\"" ba = "\033"; // escape character qDebug() << ba; // prints: "\x1B" ba = "\xC3\xA1"; qDebug() << ba; // prints: "\xC3\xA1" ba = QByteArray("a\0b", 3); qDebug() << ba // prints: "\a\x00""b"
Note how QDebug needed to close and reopen the string in the way C and C++ languages concatenate string literals so that the letter 'b' is not interpreted as part of the previous hexadecimal escape sequence.
写入指针 t , to the stream and returns a reference to the stream.
写入 flags to debug .
该函数在 Qt 4.7 引入。
Writes the contents of
list
to
debug
.
T
needs to support streaming into
QDebug
.
Writes the contents of vector
vec
to
debug
.
T
needs to support streaming into
QDebug
.
Writes the contents of vector
vec
to
debug
.
T
needs to support streaming into
QDebug
.
该函数在 Qt 5.7 引入。
Writes the contents of list
vec
to
debug
.
T
needs to support streaming into
QDebug
.
该函数在 Qt 5.7 引入。
Writes the contents of
map
to
debug
. Both
Key
and
T
need to support streaming into
QDebug
.
该函数在 Qt 5.7 引入。
Writes the contents of
map
to
debug
. Both
Key
and
T
need to support streaming into
QDebug
.
该函数在 Qt 5.7 引入。
Writes the contents of
map
to
debug
. Both
Key
and
T
need to support streaming into
QDebug
.
Writes the contents of
hash
to
debug
. Both
Key
and
T
need to support streaming into
QDebug
.
Writes the contents of
pair
to
debug
. Both
T1
and
T2
need to support streaming into
QDebug
.
Writes the contents of
set
to
debug
.
T
needs to support streaming into
QDebug
.