10#pragma qt_class(QtDebug)
13#include <QtCore/qcompare.h>
14#include <QtCore/qcontainerfwd.h>
15#include <QtCore/qfloat16.h>
16#include <QtCore/qtextstream.h>
17#include <QtCore/qttypetraits.h>
18#include <QtCore/qtypes.h>
19#include <QtCore/qstring.h>
20#include <QtCore/qcontiguouscache.h>
21#include <QtCore/qsharedpointer.h>
34#include <QtCore/q20type_traits.h>
36#include <unordered_map>
37#include <unordered_set>
40#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1
41# include <QtCore/qlist.h>
42# include <QtCore/qmap.h>
43# include <QtCore/qset.h>
44# include <QtCore/qvarlengtharray.h>
49class QT6_ONLY(Q_CORE_EXPORT) QDebug :
public QIODeviceBase
51 friend class QMessageLogger;
52 friend class QDebugStateSaver;
53 friend class QDebugStateSaverPrivate;
55 enum { VerbosityShift = 29, VerbosityMask = 0x7 };
57 explicit Stream(QIODevice *device)
60 explicit Stream(QString *string)
61 : ts(string, WriteOnly)
63 explicit Stream(QByteArray *ba)
66 explicit Stream(QtMsgType t)
67 : ts(&buffer, WriteOnly),
74 QtMsgType type = QtDebugMsg;
76 bool noQuotes =
false;
77 bool message_output =
false;
78 int verbosity = DefaultVerbosity;
79 QMessageLogContext context;
82 enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
84 QT7_ONLY(Q_CORE_EXPORT)
void putUcs4(uint ucs4);
85 QT7_ONLY(Q_CORE_EXPORT)
void putString(
const QChar *begin, size_t length);
86 QT7_ONLY(Q_CORE_EXPORT)
void putByteArray(
const char *begin, size_t length, Latin1Content content);
87 QT7_ONLY(Q_CORE_EXPORT)
void putTimeUnit(qint64 num, qint64 den);
88 QT7_ONLY(Q_CORE_EXPORT)
void putInt128(
const void *i);
89 QT7_ONLY(Q_CORE_EXPORT)
void putUInt128(
const void *i);
90 QT7_ONLY(Q_CORE_EXPORT)
void putQtOrdering(QtOrderingPrivate::QtOrderingTypeFlag flags,
91 Qt::partial_ordering order);
93 template <
typename...Ts>
94 using if_streamable = std::enable_if_t<
95 std::conjunction_v<QTypeTraits::has_ostream_operator<QDebug, Ts>...>
98 explicit QDebug(QIODevice *device) : stream(
new Stream(device)) {}
99 explicit QDebug(QString *string) : stream(
new Stream(string)) {}
100 explicit QDebug(QByteArray *bytes) : stream(
new Stream(bytes)) {}
101 explicit QDebug(QtMsgType t) : stream(
new Stream(t)) {}
102 QDebug(
const QDebug &o) : stream(o.stream) { ++stream->ref; }
103 QDebug(QDebug &&other)
noexcept : stream{std::exchange(other.stream,
nullptr)} {}
104 inline QDebug &operator=(
const QDebug &other);
105 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDebug)
107 void swap(QDebug &other)
noexcept { qt_ptr_swap(stream, other.stream); }
109 QT7_ONLY(Q_CORE_EXPORT) QDebug &resetFormat();
111 inline QDebug &space() { stream->space =
true; stream->ts <<
' ';
return *
this; }
112 inline QDebug &nospace() { stream->space =
false;
return *
this; }
113 inline QDebug &maybeSpace() {
if (stream->space) stream->ts <<
' ';
return *
this; }
114 inline QDebug &verbosity(
int verbosityLevel) { stream->verbosity = verbosityLevel;
return *
this; }
115 int verbosity()
const {
return stream->verbosity; }
116 void setVerbosity(
int verbosityLevel) { stream->verbosity = verbosityLevel; }
117 enum VerbosityLevel { MinimumVerbosity = 0, DefaultVerbosity = 2, MaximumVerbosity = 7 };
119 bool autoInsertSpaces()
const {
return stream->space; }
120 void setAutoInsertSpaces(
bool b) { stream->space = b; }
122 [[nodiscard]]
bool quoteStrings()
const noexcept {
return !stream->noQuotes; }
123 void setQuoteStrings(
bool b) { stream->noQuotes = !b; }
125 inline QDebug "e() { stream->noQuotes =
false;
return *
this; }
126 inline QDebug &noquote() { stream->noQuotes =
true;
return *
this; }
127 inline QDebug &maybeQuote(
char c =
'"') {
if (!stream->noQuotes) stream->ts << c;
return *
this; }
129 inline QDebug &operator<<(QChar t) { putUcs4(t.unicode());
return maybeSpace(); }
130 inline QDebug &operator<<(
bool t) { stream->ts << (t ?
"true" :
"false");
return maybeSpace(); }
131 inline QDebug &operator<<(
char t) { stream->ts << t;
return maybeSpace(); }
132 inline QDebug &operator<<(
signed short t) { stream->ts << t;
return maybeSpace(); }
133 inline QDebug &operator<<(
unsigned short t) { stream->ts << t;
return maybeSpace(); }
134 inline QDebug &operator<<(
char16_t t) {
return *
this << QChar(t); }
135 inline QDebug &operator<<(
char32_t t) { putUcs4(t);
return maybeSpace(); }
136 inline QDebug &operator<<(
signed int t) { stream->ts << t;
return maybeSpace(); }
137 inline QDebug &operator<<(
unsigned int t) { stream->ts << t;
return maybeSpace(); }
138 inline QDebug &operator<<(
signed long t) { stream->ts << t;
return maybeSpace(); }
139 inline QDebug &operator<<(
unsigned long t) { stream->ts << t;
return maybeSpace(); }
140 inline QDebug &operator<<(qint64 t) { stream->ts << t;
return maybeSpace(); }
141 inline QDebug &operator<<(quint64 t) { stream->ts << t;
return maybeSpace(); }
142 inline QDebug &operator<<(qfloat16 t) { stream->ts << t;
return maybeSpace(); }
143 inline QDebug &operator<<(
float t) { stream->ts << t;
return maybeSpace(); }
144 inline QDebug &operator<<(
double t) { stream->ts << t;
return maybeSpace(); }
145 inline QDebug &operator<<(
const char* t) { stream->ts << QString::fromUtf8(t);
return maybeSpace(); }
146 inline QDebug &operator<<(
const char16_t *t) { stream->ts << QStringView(t);
return maybeSpace(); }
147 inline QDebug &operator<<(
const QString & t) { putString(t.constData(), size_t(t.size()));
return maybeSpace(); }
148 inline QDebug &operator<<(QStringView s) { putString(s.data(), size_t(s.size()));
return maybeSpace(); }
149 inline QDebug &operator<<(QUtf8StringView s) { putByteArray(
reinterpret_cast<
const char*>(s.data()), s.size(), ContainsBinary);
return maybeSpace(); }
150 inline QDebug &operator<<(QLatin1StringView t) { putByteArray(t.latin1(), t.size(), ContainsLatin1);
return maybeSpace(); }
151 inline QDebug &operator<<(
const QByteArray & t) { putByteArray(t.constData(), t.size(), ContainsBinary);
return maybeSpace(); }
152 inline QDebug &operator<<(QByteArrayView t) { putByteArray(t.constData(), t.size(), ContainsBinary);
return maybeSpace(); }
153 inline QDebug &operator<<(
const void * t) { stream->ts << t;
return maybeSpace(); }
154 inline QDebug &operator<<(std::nullptr_t) { stream->ts <<
"(nullptr)";
return maybeSpace(); }
155 inline QDebug &operator<<(std::nullopt_t) { stream->ts <<
"nullopt";
return maybeSpace(); }
156 inline QDebug &operator<<(QTextStreamFunction f) {
161 inline QDebug &operator<<(QTextStreamManipulator m)
162 { stream->ts << m;
return *
this; }
165 template <
typename Char,
typename...Args>
166 QDebug &operator<<(
const std::basic_string<Char, Args...> &s);
168 template <
typename Char,
typename...Args>
169 QDebug &operator<<(std::basic_string_view<Char, Args...> s);
171 template <
typename...Args>
172 QDebug &operator<<(
const std::basic_string<
char, Args...> &s)
173 {
return *
this << QUtf8StringView(s); }
175 template <
typename...Args>
176 QDebug &operator<<(std::basic_string_view<
char, Args...> s)
177 {
return *
this << QUtf8StringView(s); }
180 template <
typename...Args>
181 QDebug &operator<<(
const std::basic_string<char8_t, Args...> &s)
182 {
return *
this << QUtf8StringView(s); }
184 template <
typename...Args>
185 QDebug &operator<<(std::basic_string_view<char8_t, Args...> s)
186 {
return *
this << QUtf8StringView(s); }
189 template <
typename...Args>
190 QDebug &operator<<(
const std::basic_string<
char16_t, Args...> &s)
191 {
return *
this << QStringView(s); }
193 template <
typename...Args>
194 QDebug &operator<<(std::basic_string_view<
char16_t, Args...> s)
195 {
return *
this << QStringView(s); }
197 template <
typename...Args>
198 QDebug &operator<<(
const std::basic_string<
wchar_t, Args...> &s)
200 if constexpr (
sizeof(
wchar_t) == 2)
201 return *
this << QStringView(s);
203 return *
this << QString::fromWCharArray(s.data(), s.size());
206 template <
typename...Args>
207 QDebug &operator<<(std::basic_string_view<
wchar_t, Args...> s)
209 if constexpr (
sizeof(
wchar_t) == 2)
210 return *
this << QStringView(s);
212 return *
this << QString::fromWCharArray(s.data(), s.size());
215 template <
typename...Args>
216 QDebug &operator<<(
const std::basic_string<
char32_t, Args...> &s)
217 {
return *
this << QString::fromUcs4(s.data(), s.size()); }
219 template <
typename...Args>
220 QDebug &operator<<(std::basic_string_view<
char32_t, Args...> s)
221 {
return *
this << QString::fromUcs4(s.data(), s.size()); }
224 template <
typename Rep,
typename Period>
225 QDebug &operator<<(std::chrono::duration<Rep, Period> duration)
227 stream->ts << duration.count();
228 putTimeUnit(Period::num, Period::den);
232#ifdef QT_SUPPORTS_INT128
236 template <
typename T>
237 using if_qint128 = std::enable_if_t<std::is_same_v<T, qint128>,
bool>;
238 template <
typename T>
239 using if_quint128 = std::enable_if_t<std::is_same_v<T, quint128>,
bool>;
241 template <
typename T, if_qint128<T> =
true>
242 QDebug &operator<<(T i128) { putInt128(&i128);
return maybeSpace(); }
243 template <
typename T, if_quint128<T> =
true>
244 QDebug &operator<<(T u128) { putUInt128(&u128);
return maybeSpace(); }
248 template <
typename T>
249 static void streamTypeErased(QDebug &d,
const void *obj)
251 d << *
static_cast<
const T*>(obj);
253 using StreamTypeErased =
void(*)(QDebug&,
const void*);
254 QT7_ONLY(Q_CORE_EXPORT)
static QString toStringImpl(StreamTypeErased s,
const void *obj);
255 QT7_ONLY(Q_CORE_EXPORT)
static QByteArray toBytesImpl(StreamTypeErased s,
const void *obj);
256 QT7_ONLY(Q_CORE_EXPORT) QDebug &putTupleLikeImplImpl(
const char *ns,
const char *what, size_t n,
257 StreamTypeErased *ops,
const void **data);
259 template <
typename TupleLike, size_t...Is>
260 QDebug &putTupleLikeImpl(
const char *ns,
const char *what,
const TupleLike &t,
261 std::index_sequence<Is...>)
263 if constexpr (
sizeof...(Is)) {
264 StreamTypeErased ops[] = {
265 &streamTypeErased<q20::remove_cvref_t<std::tuple_element_t<Is, TupleLike>>>...
267 const void *data[] = {
268 std::addressof(std::get<Is>(t))...
270 return putTupleLikeImplImpl(ns, what,
sizeof...(Is), ops, data);
272 return putTupleLikeImplImpl(ns, what, 0,
nullptr,
nullptr);
276 template <
typename TupleLike>
277 QDebug &putTupleLike(
const char *ns,
const char *what,
const TupleLike &t)
279 using Indexes = std::make_index_sequence<std::tuple_size_v<TupleLike>>;
280 return putTupleLikeImpl(ns, what, t, Indexes{});
283 template <
typename T>
284 static QString toString(
const T &object)
286 return toStringImpl(&streamTypeErased<T>, std::addressof(object));
289 template <
typename T>
290 static QByteArray toBytes(
const T &object)
292 return toBytesImpl(&streamTypeErased<T>, std::addressof(object));
295 template <
typename...Ts, if_streamable<Ts...> =
true>
296 QDebug &operator<<(
const std::tuple<Ts...> &t)
298 return putTupleLike(
"std",
"tuple", t);
301 template <
typename T, if_streamable<T> =
true>
302 QDebug &operator<<(
const std::optional<T> &o)
305 return *
this << std::nullopt;
306 StreamTypeErased s = &streamTypeErased<std::remove_cv_t<T>>;
307 const void *d = std::addressof(*o);
308 return putTupleLikeImplImpl(
"std",
"optional", 1, &s, &d);
312 template <
typename T>
313 using if_ordering_type = std::enable_if_t<QtOrderingPrivate::is_ordering_type_v<T>,
bool>;
315 template <
typename T, if_ordering_type<T> =
true>
316 friend QDebug operator<<(QDebug debug, T t)
318 debug.putQtOrdering(QtOrderingPrivate::orderingFlagsFor(t), Qt::partial_ordering(t));
326class QDebugStateSaver
329 Q_NODISCARD_CTOR Q_CORE_EXPORT
330 QDebugStateSaver(QDebug &dbg);
334 Q_DISABLE_COPY(QDebugStateSaver)
335 std::unique_ptr<QDebugStateSaverPrivate> d;
341 inline QNoDebug &operator<<(QTextStreamFunction) {
return *
this; }
342 inline QNoDebug &operator<<(QTextStreamManipulator) {
return *
this; }
343 inline QNoDebug &space() {
return *
this; }
344 inline QNoDebug &nospace() {
return *
this; }
345 inline QNoDebug &maybeSpace() {
return *
this; }
346 inline QNoDebug "e() {
return *
this; }
347 inline QNoDebug &noquote() {
return *
this; }
348 inline QNoDebug &maybeQuote(
const char =
'"') {
return *
this; }
349 inline QNoDebug &verbosity(
int) {
return *
this; }
352 inline QNoDebug &operator<<(
const T &) {
return *
this; }
355QNoDebug QMessageLogger::noDebug(...)
const noexcept
358inline QDebug &QDebug::operator=(
const QDebug &other)
360 QDebug{other}.swap(*
this);
366template <
typename SequentialContainer>
369 const QDebugStateSaver saver(debug);
370 debug.nospace() << which <<
'(';
371 typename SequentialContainer::const_iterator it = c.begin(), end = c.end();
377 debug <<
", " << *it;
384template <
typename AssociativeContainer>
387 const QDebugStateSaver saver(debug);
388 debug.nospace() << which <<
"(";
389 for (
typename AssociativeContainer::const_iterator it = c.constBegin();
390 it != c.constEnd(); ++it) {
391 debug <<
'(' << it.key() <<
", " << it.value() <<
')';
399template<
typename ...T>
400using QDebugIfHasDebugStream =
401 std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator<QDebug, T>...>, QDebug>;
403template<
typename Container,
typename ...T>
404using QDebugIfHasDebugStreamContainer =
405 std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator_container<QDebug, Container, T>...>, QDebug>;
410inline QDebugIfHasDebugStreamContainer<QList<T>, T> operator<<(QDebug debug,
const QList<T> &vec)
412 return QtPrivate::printSequentialContainer(
std::move(debug),
"QList", vec);
415template<
typename T, qsizetype P>
416inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const QVarLengthArray<T, P> &vec)
418 return QtPrivate::printSequentialContainer(
std::move(debug),
"QVarLengthArray", vec);
421template <
typename T,
typename Alloc>
422inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const std::vector<T, Alloc> &vec)
424 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::vector", vec);
427template <
typename T,
std::size_t N>
428inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const std::array<T, N> &array)
430 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::array", array);
433template <
typename T,
typename Alloc>
434inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const std::list<T, Alloc> &vec)
436 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::list", vec);
440inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
std::initializer_list<T> list)
442 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::initializer_list", list);
445template <
typename Key,
typename T,
typename Compare,
typename Alloc>
446inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug,
const std::map<Key, T, Compare, Alloc> &map)
448 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::map", map);
451template <
typename Key,
typename T,
typename Compare,
typename Alloc>
452inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug,
const std::multimap<Key, T, Compare, Alloc> &map)
454 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::multimap", map);
457template <
typename Key,
typename Compare,
typename Alloc>
458inline QDebugIfHasDebugStream<Key> operator<<(QDebug debug,
const std::multiset<Key, Compare, Alloc> &multiset)
460 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::multiset", multiset);
463template <
typename Key,
typename Compare,
typename Alloc>
464inline QDebugIfHasDebugStream<Key> operator<<(QDebug debug,
const std::set<Key, Compare, Alloc> &set)
466 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::set", set);
469template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
typename Alloc>
470inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug,
const std::unordered_map<Key, T, Hash, KeyEqual, Alloc> &unordered_map)
472 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::unordered_map", unordered_map);
475template <
typename Key,
typename Hash,
typename KeyEqual,
typename Alloc>
476inline QDebugIfHasDebugStream<Key> operator<<(QDebug debug,
const std::unordered_set<Key, Hash, KeyEqual, Alloc> &unordered_set)
478 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::unordered_set", unordered_set);
481template <
class Key,
class T>
482inline QDebugIfHasDebugStreamContainer<QMap<Key, T>, Key, T> operator<<(QDebug debug,
const QMap<Key, T> &map)
484 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QMap", map);
487template <
class Key,
class T>
488inline QDebugIfHasDebugStreamContainer<QMultiMap<Key, T>, Key, T> operator<<(QDebug debug,
const QMultiMap<Key, T> &map)
490 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QMultiMap", map);
493template <
class Key,
class T>
494inline QDebugIfHasDebugStreamContainer<QHash<Key, T>, Key, T> operator<<(QDebug debug,
const QHash<Key, T> &hash)
496 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QHash", hash);
499template <
class Key,
class T>
500inline QDebugIfHasDebugStreamContainer<QMultiHash<Key, T>, Key, T> operator<<(QDebug debug,
const QMultiHash<Key, T> &hash)
502 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QMultiHash", hash);
505template <
class T1,
class T2>
506inline QDebugIfHasDebugStream<T1, T2> operator<<(QDebug debug,
const std::pair<T1, T2> &pair)
508 const QDebugStateSaver saver(debug);
509 debug.nospace() <<
"std::pair(" << pair.first <<
", " << pair.second <<
')';
514inline QDebugIfHasDebugStreamContainer<QSet<T>, T> operator<<(QDebug debug,
const QSet<T> &set)
516 return QtPrivate::printSequentialContainer(
std::move(debug),
"QSet", set);
520inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const QContiguousCache<T> &cache)
522 const QDebugStateSaver saver(debug);
523 debug.nospace() <<
"QContiguousCache(";
524 for (qsizetype i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
526 if (i != cache.lastIndex())
535QDebug operator<<(QDebug debug,
const QList<T> &list);
537template <
class T, qsizetype P>
538QDebug operator<<(QDebug debug,
const QVarLengthArray<T, P> &array);
540template <
typename T,
typename Alloc>
541QDebug operator<<(QDebug debug,
const std::vector<T, Alloc> &vec);
543template <
typename T, std::size_t N>
544QDebug operator<<(QDebug debug,
const std::array<T, N> &array);
546template <
typename T,
typename Alloc>
547QDebug operator<<(QDebug debug,
const std::list<T, Alloc> &vec);
549template <
typename Key,
typename T,
typename Compare,
typename Alloc>
550QDebug operator<<(QDebug debug,
const std::map<Key, T, Compare, Alloc> &map);
552template <
typename Key,
typename T,
typename Compare,
typename Alloc>
553QDebug operator<<(QDebug debug,
const std::multimap<Key, T, Compare, Alloc> &map);
555template <
class Key,
class T>
556QDebug operator<<(QDebug debug,
const QMap<Key, T> &map);
558template <
class Key,
class T>
559QDebug operator<<(QDebug debug,
const QMultiMap<Key, T> &map);
561template <
class Key,
class T>
562QDebug operator<<(QDebug debug,
const QHash<Key, T> &hash);
564template <
class Key,
class T>
565QDebug operator<<(QDebug debug,
const QMultiHash<Key, T> &hash);
568QDebug operator<<(QDebug debug,
const QSet<T> &set);
570template <
class T1,
class T2>
571QDebug operator<<(QDebug debug,
const std::pair<T1, T2> &pair);
574QDebug operator<<(QDebug debug,
const QContiguousCache<T> &cache);
576template <
typename Key,
typename Compare,
typename Alloc>
577QDebug operator<<(QDebug debug,
const std::multiset<Key, Compare, Alloc> &multiset);
579template <
typename Key,
typename Compare,
typename Alloc>
580QDebug operator<<(QDebug debug,
const std::set<Key, Compare, Alloc> &set);
582template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
typename Alloc>
583QDebug operator<<(QDebug debug,
const std::unordered_map<Key, T, Hash, KeyEqual, Alloc> &unordered_map);
585template <
typename Key,
typename Hash,
typename KeyEqual,
typename Alloc>
586QDebug operator<<(QDebug debug,
const std::unordered_set<Key, Hash, KeyEqual, Alloc> &unordered_set);
591inline QDebug operator<<(QDebug debug,
const QSharedPointer<T> &ptr)
593 QDebugStateSaver saver(debug);
594 debug.nospace() <<
"QSharedPointer(" << ptr.data() <<
")";
600template <
typename T,
typename Tag>
603 QDebugStateSaver saver(debug);
604 debug.nospace() <<
"QTaggedPointer(" << ptr.pointer() <<
", " << ptr.tag() <<
")";
608Q_CORE_EXPORT
QDebug qt_QMetaEnum_debugOperator(QDebug&, qint64 value,
const QMetaObject *meta,
const char *name);
609Q_CORE_EXPORT
QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value,
const QMetaObject *meta,
const char *name);
613template <
typename Int>
616 static_assert(
std::is_unsigned_v<Int>,
617 "Cast value to an unsigned type before calling this function");
618 const QDebugStateSaver saver(debug);
620 debug.nospace() <<
"QFlags(" << Qt::hex << Qt::showbase;
621 bool needSeparator =
false;
622 for (size_t i = 0; i < sizeofT * 8; ++i) {
623 if (value & (Int(1) << i)) {
627 needSeparator =
true;
628 debug << (Int(1) << i);
634template <
class Flags,
635 std::enable_if_t<QtPrivate::IsQFlags<Flags>::value,
bool> =
true>
636inline QDebug operator<<(QDebug debug, Flags flags)
638 using T =
typename Flags::enum_type;
639 using UInt =
typename QIntegerForSizeof<T>::Unsigned;
640#if !defined(QT_NO_QOBJECT)
641 if constexpr (QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<Flags>::Value) {
644 using Int = std::conditional_t<QtPrivate::IsQEnumHelper<Flags>::Value, UInt,
645 std::underlying_type_t<T>>;
646 const QMetaObject *obj = qt_getEnumMetaObject(T());
647 const char *name = qt_getEnumName(T());
648 return qt_QMetaEnum_flagDebugOperator(debug, Int(flags.toInt()), obj, name);
652 qt_QMetaEnum_flagDebugOperator(debug,
sizeof(T), UInt(flags.toInt()));
659QDebug operator<<(QDebug debug,
const QFlags<T> &flags);
662#if !defined(QT_NO_QOBJECT) && !defined(Q_QDOC)
684std::enable_if_t<QtPrivate::EnumHasQFlag<T>::Value, QDebug>
685operator<<(QDebug debug, T flag)
687 return debug << QFlags(flag);
691std::enable_if_t<QtPrivate::EnumHasQEnum<T>::Value, QDebug>
692operator<<(QDebug dbg, T value)
694 const QMetaObject *obj = qt_getEnumMetaObject(value);
695 const char *name = qt_getEnumName(value);
696 return qt_QMetaEnum_debugOperator(dbg,
static_cast<
typename std::underlying_type<T>::type>(value), obj, name);
700inline QDebug operator<<(QDebug debug, QKeyCombination combination)
702 QDebugStateSaver saver(debug);
703 debug.nospace() <<
"QKeyCombination("
704 << combination.keyboardModifiers()
717#define QT_FOR_EACH_CORE_FOUNDATION_TYPE(F)
728#define QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(F)
732#define QT_FOR_EACH_CORE_GRAPHICS_TYPE(F)
735#define QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(F)
741#define QT_FORWARD_DECLARE_CF_TYPE(type) Q_FORWARD_DECLARE_CF_TYPE(type);
742#define QT_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type);
743#define QT_FORWARD_DECLARE_CG_TYPE(type) Q_FORWARD_DECLARE_CG_TYPE(type);
744#define QT_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type);
747Q_FORWARD_DECLARE_CF_TYPE(CFString);
749Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
750QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_CF_TYPE)
751QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_MUTABLE_CF_TYPE)
752QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_CG_TYPE)
753QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_MUTABLE_CG_TYPE)
756#define QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType)
757 Q_CORE_EXPORT QDebug operator
<<(QDebug, CFType##Ref);
759#define Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType)
760 QDebug operator
<<(QDebug debug, CFType##Ref ref)
763 return debug << QT_STRINGIFY(CFType) "Ref(0x0)";
764 if (CFStringRef description = CFCopyDescription(ref)) {
765 QDebugStateSaver saver(debug);
766 debug.noquote() << description;
767 CFRelease(description);
774Q_CORE_EXPORT QDebug operator<<(QDebug, id);
776Q_CORE_EXPORT QDebug operator<<(QDebug, objc_object *);
777Q_CORE_EXPORT QDebug operator<<(QDebug,
const NSObject *);
778Q_CORE_EXPORT QDebug operator<<(QDebug, CFStringRef);
780QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
781QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
782QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
783QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
785#undef QT_FORWARD_DECLARE_CF_TYPE
786#undef QT_FORWARD_DECLARE_MUTABLE_CF_TYPE
787#undef QT_FORWARD_DECLARE_CG_TYPE
788#undef QT_FORWARD_DECLARE_MUTABLE_CG_TYPE
QByteArray & operator*() noexcept
QByteArray::Base64DecodingStatus decodingStatus
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
void swap(QByteArray::FromBase64Result &other) noexcept
operator bool() const noexcept
\variable QByteArray::FromBase64Result::decoded
const QByteArray & operator*() const noexcept
Returns the decoded byte array.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
\inmodule QtCore\reentrant
int initFrom(const QMessageLogContext &logContext)
void populateBacktrace(int frameCount)
QInternalMessageLogContext(const QMessageLogContext &logContext, const QLoggingCategory &categoryOverride)
std::optional< BacktraceStorage > backtrace
static constexpr int DefaultBacktraceDepth
constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
constexpr QMessageLogContext() noexcept=default
QDebug debug(CategoryFunction catFunc) const
QDebug debug(const QLoggingCategory &cat) const
Logs a debug message into category cat using a QDebug stream.
void void void void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION void QDebug debug() const
Logs a debug message using a QDebug stream.
QDebug info(const QLoggingCategory &cat) const
Logs an informational message into the category cat using a QDebug stream.
QDebug info() const
Logs an informational message using a QDebug stream.
QNoDebug noDebug(...) const noexcept
QDebug info(CategoryFunction catFunc) const
static Q_CONSTINIT thread_local bool msgHandlerGrabbed
static const char ifCriticalTokenC[]
static bool grabMessageHandler()
void qt_message_output(QtMsgType msgType, const QMessageLogContext &context, const QString &message)
static const char emptyTokenC[]
static Q_NEVER_INLINE void qt_message(QtMsgType msgType, const QMessageLogContext &context, const char *msg, va_list ap)
static void preformattedMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static bool systemHasStderr()
Returns true if writing to stderr is supported.
static const char endifTokenC[]
static bool isDefaultCategory(const char *category)
static const char messageTokenC[]
static bool qt_append_thread_name_to(QString &message)
static constexpr SystemMessageSink systemMessageSink
static void qt_maybe_message_fatal(QtMsgType, const QMessageLogContext &context, String &&message)
\inmodule QtCore \title Qt Logging Types
#define HANDLE_IF_TOKEN(LEVEL)
Q_DECLARE_TYPEINFO(QMessagePattern::BacktraceParams, Q_RELOCATABLE_TYPE)
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &buf)
static const char timeTokenC[]
static bool isFatalCountDown(const char *varname, QBasicAtomicInt &n)
void qErrnoWarning(int code, const char *msg,...)
static const char qthreadptrTokenC[]
static const char fileTokenC[]
static const char ifDebugTokenC[]
static const char ifFatalTokenC[]
static const char categoryTokenC[]
static void stderr_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &formattedMessage)
static const char lineTokenC[]
static const char typeTokenC[]
static void ungrabMessageHandler()
static void copyInternalContext(QInternalMessageLogContext *self, const QMessageLogContext &logContext) noexcept
static const char ifCategoryTokenC[]
static int checked_var_value(const char *varname)
static const char threadnameTokenC[]
static const char pidTokenC[]
Q_TRACE_POINT(qtcore, qt_message_print, int type, const char *category, const char *function, const char *file, int line, const QString &message)
static const char threadidTokenC[]
static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
static const char backtraceTokenC[]
void qErrnoWarning(const char *msg,...)
static const char functionTokenC[]
static const char ifWarningTokenC[]
static const char appnameTokenC[]
static bool isFatal(QtMsgType msgType)
static const char ifInfoTokenC[]
QtMessageHandler qInstallMessageHandler(QtMessageHandler h)
static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message)
static bool stderrHasConsoleAttached()
Returns true if writing to stderr will end up in a console/terminal visible to the user.
void qSetMessagePattern(const QString &pattern)
QDebug printAssociativeContainer(QDebug debug, const char *which, const AssociativeContainer &c)
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
QDebug printSequentialContainer(QDebug debug, const char *which, const SequentialContainer &c)
QByteArray operator""_ba(const char *str, size_t size) noexcept
QByteArray operator+(const QByteArray &a1, const char *a2)
QByteArray qUncompress(const QByteArray &data)
QByteArray operator+(char a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, char rhs)
QByteArray operator+(const QByteArray &a1, char a2)
QByteArray operator+(const char *a1, const QByteArray &a2)
QByteArray operator+(QByteArray &&lhs, const QByteArray &rhs)
qsizetype erase_if(QByteArray &ba, Predicate pred)
QByteArray operator+(const QByteArray &a1, const QByteArray &a2)
QByteArray qCompress(const QByteArray &data, int compressionLevel=-1)
qsizetype erase(QByteArray &ba, const T &t)
QByteArray operator+(QByteArray &&lhs, const char *rhs)
#define __has_cpp_attribute(x)
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, Int value)
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, quint64 value)
Q_CORE_EXPORT void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
#define QT_MESSAGELOG_FUNC
#define QT_MESSAGELOG_FILE
#define QT_MESSAGE_LOGGER_NORETURN
#define QT_MESSAGELOG_LINE
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
#define QT_MESSAGELOGCONTEXT
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
QString backtraceSeparator
void setPattern(const QString &pattern)
std::unique_ptr< std::unique_ptr< const char[]>[]> literals
std::chrono::steady_clock::time_point appStartTime
std::unique_ptr< const char *[]> tokens
QList< QString > timeArgs
static constexpr bool Value
static constexpr bool Value