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>
33#include <system_error>
35#include <QtCore/q20type_traits.h>
37#include <unordered_map>
38#include <unordered_set>
41#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 1
42# include <QtCore/qlist.h>
43# include <QtCore/qmap.h>
44# include <QtCore/qset.h>
45# include <QtCore/qvarlengtharray.h>
49Q_FORWARD_DECLARE_OBJC_CLASS(NSString);
54class QT6_ONLY(Q_CORE_EXPORT) QDebug :
public QIODeviceBase
56 friend class QMessageLogger;
57 friend class QDebugStateSaver;
58 friend class QDebugStateSaverPrivate;
60 enum { VerbosityShift = 29, VerbosityMask = 0x7 };
62 explicit Stream(QIODevice *device)
65 explicit Stream(QString *string)
66 : ts(string, WriteOnly)
68 explicit Stream(QByteArray *ba)
71 explicit Stream(QtMsgType t)
72 : ts(&buffer, WriteOnly),
79 QtMsgType type = QtDebugMsg;
81 bool noQuotes =
false;
82 bool message_output =
false;
83 int verbosity = DefaultVerbosity;
84 QMessageLogContext context;
87 enum Latin1Content { ContainsBinary = 0, ContainsLatin1 };
89 QT7_ONLY(Q_CORE_EXPORT)
void putUcs4(uint ucs4);
90 QT7_ONLY(Q_CORE_EXPORT)
void putString(
const QChar *begin, size_t length);
91 QT7_ONLY(Q_CORE_EXPORT)
void putByteArray(
const char *begin, size_t length, Latin1Content content);
92 QT7_ONLY(Q_CORE_EXPORT)
void putTimeUnit(qint64 num, qint64 den);
93 QT7_ONLY(Q_CORE_EXPORT)
void putInt128(
const void *i);
94 QT7_ONLY(Q_CORE_EXPORT)
void putUInt128(
const void *i);
95 QT7_ONLY(Q_CORE_EXPORT)
void putQtOrdering(QtOrderingPrivate::QtOrderingTypeFlag flags,
96 Qt::partial_ordering order);
98 template <
typename...Ts>
99 using if_streamable = std::enable_if_t<
100 std::conjunction_v<QTypeTraits::has_ostream_operator<QDebug, Ts>...>
103 explicit QDebug(QIODevice *device) : stream(
new Stream(device)) {}
104 explicit QDebug(QString *string) : stream(
new Stream(string)) {}
105 explicit QDebug(QByteArray *bytes) : stream(
new Stream(bytes)) {}
106 explicit QDebug(QtMsgType t) : stream(
new Stream(t)) {}
107 QDebug(
const QDebug &o) : stream(o.stream) { ++stream->ref; }
108 QDebug(QDebug &&other)
noexcept : stream{std::exchange(other.stream,
nullptr)} {}
109 inline QDebug &operator=(
const QDebug &other);
110 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QDebug)
112 void swap(QDebug &other)
noexcept { qt_ptr_swap(stream, other.stream); }
114 QT7_ONLY(Q_CORE_EXPORT) QDebug &resetFormat();
116 inline QDebug &space() { stream->space =
true; stream->ts <<
' ';
return *
this; }
117 inline QDebug &nospace() { stream->space =
false;
return *
this; }
118 inline QDebug &maybeSpace() {
if (stream->space) stream->ts <<
' ';
return *
this; }
119 inline QDebug &verbosity(
int verbosityLevel) { stream->verbosity = verbosityLevel;
return *
this; }
120 int verbosity()
const {
return stream->verbosity; }
121 void setVerbosity(
int verbosityLevel) { stream->verbosity = verbosityLevel; }
122 enum VerbosityLevel { MinimumVerbosity = 0, DefaultVerbosity = 2, MaximumVerbosity = 7 };
124 bool autoInsertSpaces()
const {
return stream->space; }
125 void setAutoInsertSpaces(
bool b) { stream->space = b; }
127 [[nodiscard]]
bool quoteStrings()
const noexcept {
return !stream->noQuotes; }
128 void setQuoteStrings(
bool b) { stream->noQuotes = !b; }
130 inline QDebug "e() { stream->noQuotes =
false;
return *
this; }
131 inline QDebug &noquote() { stream->noQuotes =
true;
return *
this; }
132 inline QDebug &maybeQuote(
char c =
'"') {
if (!stream->noQuotes) stream->ts << c;
return *
this; }
134 inline QDebug &operator<<(QChar t) { putUcs4(t.unicode());
return maybeSpace(); }
135 inline QDebug &operator<<(
bool t) { stream->ts << (t ?
"true" :
"false");
return maybeSpace(); }
136 inline QDebug &operator<<(
char t) { stream->ts << t;
return maybeSpace(); }
137 inline QDebug &operator<<(
signed short t) { stream->ts << t;
return maybeSpace(); }
138 inline QDebug &operator<<(
unsigned short t) { stream->ts << t;
return maybeSpace(); }
139 inline QDebug &operator<<(
char16_t t) {
return *
this << QChar(t); }
140 inline QDebug &operator<<(
char32_t t) { putUcs4(t);
return maybeSpace(); }
141 inline QDebug &operator<<(
signed int t) { stream->ts << t;
return maybeSpace(); }
142 inline QDebug &operator<<(
unsigned int t) { stream->ts << t;
return maybeSpace(); }
143 inline QDebug &operator<<(
signed long t) { stream->ts << t;
return maybeSpace(); }
144 inline QDebug &operator<<(
unsigned long t) { stream->ts << t;
return maybeSpace(); }
145 inline QDebug &operator<<(qint64 t) { stream->ts << t;
return maybeSpace(); }
146 inline QDebug &operator<<(quint64 t) { stream->ts << t;
return maybeSpace(); }
147 inline QDebug &operator<<(qfloat16 t) { stream->ts << t;
return maybeSpace(); }
148 inline QDebug &operator<<(
float t) { stream->ts << t;
return maybeSpace(); }
149 inline QDebug &operator<<(
double t) { stream->ts << t;
return maybeSpace(); }
150 inline QDebug &operator<<(
const char* t) { stream->ts << QString::fromUtf8(t);
return maybeSpace(); }
151 inline QDebug &operator<<(
const char16_t *t) { stream->ts << QStringView(t);
return maybeSpace(); }
152 inline QDebug &operator<<(
const QString & t) { putString(t.constData(), size_t(t.size()));
return maybeSpace(); }
153 inline QDebug &operator<<(QStringView s) { putString(s.data(), size_t(s.size()));
return maybeSpace(); }
154 inline QDebug &operator<<(QUtf8StringView s) { putByteArray(
reinterpret_cast<
const char*>(s.data()), s.size(), ContainsBinary);
return maybeSpace(); }
155 inline QDebug &operator<<(QLatin1StringView t) { putByteArray(t.latin1(), t.size(), ContainsLatin1);
return maybeSpace(); }
156 inline QDebug &operator<<(
const QByteArray & t) { putByteArray(t.constData(), t.size(), ContainsBinary);
return maybeSpace(); }
157 inline QDebug &operator<<(QByteArrayView t) { putByteArray(t.constData(), t.size(), ContainsBinary);
return maybeSpace(); }
158 inline QDebug &operator<<(
const void * t) { stream->ts << t;
return maybeSpace(); }
159 inline QDebug &operator<<(std::nullptr_t) { stream->ts <<
"(nullptr)";
return maybeSpace(); }
160 inline QDebug &operator<<(std::nullopt_t) { stream->ts <<
"nullopt";
return maybeSpace(); }
161 inline QDebug &operator<<(QTextStreamFunction f) {
166 inline QDebug &operator<<(QTextStreamManipulator m)
167 { stream->ts << m;
return *
this; }
170 template <
typename Char,
typename...Args>
171 QDebug &operator<<(
const std::basic_string<Char, Args...> &s);
173 template <
typename Char,
typename...Args>
174 QDebug &operator<<(std::basic_string_view<Char, Args...> s);
176 template <
typename...Args>
177 QDebug &operator<<(
const std::basic_string<
char, Args...> &s)
178 {
return *
this << QUtf8StringView(s); }
180 template <
typename...Args>
181 QDebug &operator<<(std::basic_string_view<
char, Args...> s)
182 {
return *
this << QUtf8StringView(s); }
185 template <
typename...Args>
186 QDebug &operator<<(
const std::basic_string<char8_t, Args...> &s)
187 {
return *
this << QUtf8StringView(s); }
189 template <
typename...Args>
190 QDebug &operator<<(std::basic_string_view<char8_t, Args...> s)
191 {
return *
this << QUtf8StringView(s); }
194 template <
typename...Args>
195 QDebug &operator<<(
const std::basic_string<
char16_t, Args...> &s)
196 {
return *
this << QStringView(s); }
198 template <
typename...Args>
199 QDebug &operator<<(std::basic_string_view<
char16_t, Args...> s)
200 {
return *
this << QStringView(s); }
202 template <
typename...Args>
203 QDebug &operator<<(
const std::basic_string<
wchar_t, Args...> &s)
205 if constexpr (
sizeof(
wchar_t) == 2)
206 return *
this << QStringView(s);
208 return *
this << QString::fromWCharArray(s.data(), s.size());
211 template <
typename...Args>
212 QDebug &operator<<(std::basic_string_view<
wchar_t, Args...> s)
214 if constexpr (
sizeof(
wchar_t) == 2)
215 return *
this << QStringView(s);
217 return *
this << QString::fromWCharArray(s.data(), s.size());
220 template <
typename...Args>
221 QDebug &operator<<(
const std::basic_string<
char32_t, Args...> &s)
222 {
return *
this << QString::fromUcs4(s.data(), s.size()); }
224 template <
typename...Args>
225 QDebug &operator<<(std::basic_string_view<
char32_t, Args...> s)
226 {
return *
this << QString::fromUcs4(s.data(), s.size()); }
229 template <
typename Rep,
typename Period>
230 QDebug &operator<<(std::chrono::duration<Rep, Period> duration)
232 stream->ts << duration.count();
233 putTimeUnit(Period::num, Period::den);
237#ifdef QT_SUPPORTS_INT128
241 template <
typename T>
242 using if_qint128 = std::enable_if_t<std::is_same_v<T, qint128>,
bool>;
243 template <
typename T>
244 using if_quint128 = std::enable_if_t<std::is_same_v<T, quint128>,
bool>;
246 template <
typename T, if_qint128<T> =
true>
247 QDebug &operator<<(T i128) { putInt128(&i128);
return maybeSpace(); }
248 template <
typename T, if_quint128<T> =
true>
249 QDebug &operator<<(T u128) { putUInt128(&u128);
return maybeSpace(); }
253 template <
typename T>
254 static void streamTypeErased(QDebug &d,
const void *obj)
256 d << *
static_cast<
const T*>(obj);
258 using StreamTypeErased =
void(*)(QDebug&,
const void*);
259 QT7_ONLY(Q_CORE_EXPORT)
static QString toStringImpl(StreamTypeErased s,
const void *obj);
260 QT7_ONLY(Q_CORE_EXPORT)
static QByteArray toBytesImpl(StreamTypeErased s,
const void *obj);
261 QT7_ONLY(Q_CORE_EXPORT) QDebug &putTupleLikeImplImpl(
const char *ns,
const char *what, size_t n,
262 StreamTypeErased *ops,
const void **data);
264 template <
typename TupleLike, size_t...Is>
265 QDebug &putTupleLikeImpl(
const char *ns,
const char *what,
const TupleLike &t,
266 std::index_sequence<Is...>)
268 if constexpr (
sizeof...(Is)) {
269 StreamTypeErased ops[] = {
270 &streamTypeErased<q20::remove_cvref_t<std::tuple_element_t<Is, TupleLike>>>...
272 const void *data[] = {
273 std::addressof(std::get<Is>(t))...
275 return putTupleLikeImplImpl(ns, what,
sizeof...(Is), ops, data);
277 return putTupleLikeImplImpl(ns, what, 0,
nullptr,
nullptr);
281 template <
typename TupleLike>
282 QDebug &putTupleLike(
const char *ns,
const char *what,
const TupleLike &t)
284 using Indexes = std::make_index_sequence<std::tuple_size_v<TupleLike>>;
285 return putTupleLikeImpl(ns, what, t, Indexes{});
288 template <
typename T>
289 static QString toString(
const T &object)
291 return toStringImpl(&streamTypeErased<T>, std::addressof(object));
294 template <
typename T>
295 static QByteArray toBytes(
const T &object)
297 return toBytesImpl(&streamTypeErased<T>, std::addressof(object));
300 template <
typename...Ts, if_streamable<Ts...> =
true>
301 QDebug &operator<<(
const std::tuple<Ts...> &t)
303 return putTupleLike(
"std",
"tuple", t);
306 template <
typename T, if_streamable<T> =
true>
307 QDebug &operator<<(
const std::optional<T> &o)
310 return *
this << std::nullopt;
311 StreamTypeErased s = &streamTypeErased<std::remove_cv_t<T>>;
312 const void *d = std::addressof(*o);
313 return putTupleLikeImplImpl(
"std",
"optional", 1, &s, &d);
317 template <
typename T>
318 using if_ordering_type = std::enable_if_t<QtOrderingPrivate::is_ordering_type_v<T>,
bool>;
320 template <
typename T, if_ordering_type<T> =
true>
321 friend QDebug operator<<(QDebug debug, T t)
323 debug.putQtOrdering(QtOrderingPrivate::orderingFlagsFor(t), Qt::partial_ordering(t));
327 Q_CORE_EXPORT
friend QDebug operator<<(QDebug debug,
const std::error_code &code);
328 Q_CORE_EXPORT
friend QDebug operator<<(QDebug debug,
const std::error_condition &condition);
331 Q_CORE_EXPORT
friend QDebug operator<<(QDebug,
const NSString *);
338class QDebugStateSaver
341 Q_NODISCARD_CTOR Q_CORE_EXPORT
342 QDebugStateSaver(QDebug &dbg);
346 Q_DISABLE_COPY(QDebugStateSaver)
347 std::unique_ptr<QDebugStateSaverPrivate> d;
353 inline QNoDebug &operator<<(QTextStreamFunction) {
return *
this; }
354 inline QNoDebug &operator<<(QTextStreamManipulator) {
return *
this; }
355 inline QNoDebug &space() {
return *
this; }
356 inline QNoDebug &nospace() {
return *
this; }
357 inline QNoDebug &maybeSpace() {
return *
this; }
358 inline QNoDebug "e() {
return *
this; }
359 inline QNoDebug &noquote() {
return *
this; }
360 inline QNoDebug &maybeQuote(
const char =
'"') {
return *
this; }
361 inline QNoDebug &verbosity(
int) {
return *
this; }
364 inline QNoDebug &operator<<(
const T &) {
return *
this; }
367QNoDebug QMessageLogger::noDebug(...)
const noexcept
370inline QDebug &QDebug::operator=(
const QDebug &other)
372 QDebug{other}.swap(*
this);
378template <
typename SequentialContainer>
379inline QDebug printSequentialContainer(QDebug debug,
const char *which,
const SequentialContainer &c)
381 const QDebugStateSaver saver(debug);
382 debug.nospace() << which <<
'(';
383 typename SequentialContainer::const_iterator it = c.begin(), end = c.end();
389 debug <<
", " << *it;
396template <
typename AssociativeContainer>
397inline QDebug printAssociativeContainer(QDebug debug,
const char *which,
const AssociativeContainer &c)
399 const QDebugStateSaver saver(debug);
400 debug.nospace() << which <<
"(";
401 for (
typename AssociativeContainer::const_iterator it = c.constBegin();
402 it != c.constEnd(); ++it) {
403 debug <<
'(' << it.key() <<
", " << it.value() <<
')';
411template<
typename ...T>
412using QDebugIfHasDebugStream =
413 std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator<QDebug, T>...>, QDebug>;
415template<
typename Container,
typename ...T>
416using QDebugIfHasDebugStreamContainer =
417 std::enable_if_t<std::conjunction_v<QTypeTraits::has_ostream_operator_container<QDebug, Container, T>...>, QDebug>;
422inline QDebugIfHasDebugStreamContainer<QList<T>, T> operator<<(QDebug debug,
const QList<T> &vec)
424 return QtPrivate::printSequentialContainer(
std::move(debug),
"QList", vec);
427template<
typename T, qsizetype P>
428inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const QVarLengthArray<T, P> &vec)
430 return QtPrivate::printSequentialContainer(
std::move(debug),
"QVarLengthArray", vec);
433template <
typename T,
typename Alloc>
434inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const std::vector<T, Alloc> &vec)
436 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::vector", vec);
439template <
typename T,
std::size_t N>
440inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const std::array<T, N> &array)
442 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::array", array);
445template <
typename T,
typename Alloc>
446inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const std::list<T, Alloc> &vec)
448 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::list", vec);
452inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
std::initializer_list<T> list)
454 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::initializer_list", list);
457template <
typename Key,
typename T,
typename Compare,
typename Alloc>
458inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug,
const std::map<Key, T, Compare, Alloc> &map)
460 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::map", map);
463template <
typename Key,
typename T,
typename Compare,
typename Alloc>
464inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug,
const std::multimap<Key, T, Compare, Alloc> &map)
466 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::multimap", map);
469template <
typename Key,
typename Compare,
typename Alloc>
470inline QDebugIfHasDebugStream<Key> operator<<(QDebug debug,
const std::multiset<Key, Compare, Alloc> &multiset)
472 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::multiset", multiset);
475template <
typename Key,
typename Compare,
typename Alloc>
476inline QDebugIfHasDebugStream<Key> operator<<(QDebug debug,
const std::set<Key, Compare, Alloc> &set)
478 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::set", set);
481template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
typename Alloc>
482inline QDebugIfHasDebugStream<Key, T> operator<<(QDebug debug,
const std::unordered_map<Key, T, Hash, KeyEqual, Alloc> &unordered_map)
484 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::unordered_map", unordered_map);
487template <
typename Key,
typename Hash,
typename KeyEqual,
typename Alloc>
488inline QDebugIfHasDebugStream<Key> operator<<(QDebug debug,
const std::unordered_set<Key, Hash, KeyEqual, Alloc> &unordered_set)
490 return QtPrivate::printSequentialContainer(
std::move(debug),
"std::unordered_set", unordered_set);
493template <
class Key,
class T>
494inline QDebugIfHasDebugStreamContainer<QMap<Key, T>, Key, T> operator<<(QDebug debug,
const QMap<Key, T> &map)
496 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QMap", map);
499template <
class Key,
class T>
500inline QDebugIfHasDebugStreamContainer<QMultiMap<Key, T>, Key, T> operator<<(QDebug debug,
const QMultiMap<Key, T> &map)
502 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QMultiMap", map);
505template <
class Key,
class T>
506inline QDebugIfHasDebugStreamContainer<QHash<Key, T>, Key, T> operator<<(QDebug debug,
const QHash<Key, T> &hash)
508 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QHash", hash);
511template <
class Key,
class T>
512inline QDebugIfHasDebugStreamContainer<QMultiHash<Key, T>, Key, T> operator<<(QDebug debug,
const QMultiHash<Key, T> &hash)
514 return QtPrivate::printAssociativeContainer(
std::move(debug),
"QMultiHash", hash);
517template <
class T1,
class T2>
518inline QDebugIfHasDebugStream<T1, T2> operator<<(QDebug debug,
const std::pair<T1, T2> &pair)
520 const QDebugStateSaver saver(debug);
521 debug.nospace() <<
"std::pair(" << pair.first <<
", " << pair.second <<
')';
526inline QDebugIfHasDebugStreamContainer<QSet<T>, T> operator<<(QDebug debug,
const QSet<T> &set)
528 return QtPrivate::printSequentialContainer(
std::move(debug),
"QSet", set);
532inline QDebugIfHasDebugStream<T> operator<<(QDebug debug,
const QContiguousCache<T> &cache)
534 const QDebugStateSaver saver(debug);
535 debug.nospace() <<
"QContiguousCache(";
536 for (qsizetype i = cache.firstIndex(); i <= cache.lastIndex(); ++i) {
538 if (i != cache.lastIndex())
547QDebug operator<<(QDebug debug,
const QList<T> &list);
549template <
class T, qsizetype P>
550QDebug operator<<(QDebug debug,
const QVarLengthArray<T, P> &array);
552template <
typename T,
typename Alloc>
553QDebug operator<<(QDebug debug,
const std::vector<T, Alloc> &vec);
555template <
typename T, std::size_t N>
556QDebug operator<<(QDebug debug,
const std::array<T, N> &array);
558template <
typename T,
typename Alloc>
559QDebug operator<<(QDebug debug,
const std::list<T, Alloc> &vec);
561template <
typename Key,
typename T,
typename Compare,
typename Alloc>
562QDebug operator<<(QDebug debug,
const std::map<Key, T, Compare, Alloc> &map);
564template <
typename Key,
typename T,
typename Compare,
typename Alloc>
565QDebug operator<<(QDebug debug,
const std::multimap<Key, T, Compare, Alloc> &map);
567template <
class Key,
class T>
568QDebug operator<<(QDebug debug,
const QMap<Key, T> &map);
570template <
class Key,
class T>
571QDebug operator<<(QDebug debug,
const QMultiMap<Key, T> &map);
573template <
class Key,
class T>
574QDebug operator<<(QDebug debug,
const QHash<Key, T> &hash);
576template <
class Key,
class T>
577QDebug operator<<(QDebug debug,
const QMultiHash<Key, T> &hash);
580QDebug operator<<(QDebug debug,
const QSet<T> &set);
582template <
class T1,
class T2>
583QDebug operator<<(QDebug debug,
const std::pair<T1, T2> &pair);
586QDebug operator<<(QDebug debug,
const QContiguousCache<T> &cache);
588template <
typename Key,
typename Compare,
typename Alloc>
589QDebug operator<<(QDebug debug,
const std::multiset<Key, Compare, Alloc> &multiset);
591template <
typename Key,
typename Compare,
typename Alloc>
592QDebug operator<<(QDebug debug,
const std::set<Key, Compare, Alloc> &set);
594template <
typename Key,
typename T,
typename Hash,
typename KeyEqual,
typename Alloc>
595QDebug operator<<(QDebug debug,
const std::unordered_map<Key, T, Hash, KeyEqual, Alloc> &unordered_map);
597template <
typename Key,
typename Hash,
typename KeyEqual,
typename Alloc>
598QDebug operator<<(QDebug debug,
const std::unordered_set<Key, Hash, KeyEqual, Alloc> &unordered_set);
603inline QDebug operator<<(QDebug debug,
const QSharedPointer<T> &ptr)
605 QDebugStateSaver saver(debug);
606 debug.nospace() <<
"QSharedPointer(" << ptr.data() <<
")";
612template <
typename T,
typename Tag>
615 QDebugStateSaver saver(debug);
616 debug.nospace() <<
"QTaggedPointer(" << ptr.pointer() <<
", " << ptr.tag() <<
")";
620Q_CORE_EXPORT QDebug qt_QMetaEnum_debugOperator(QDebug&, qint64 value,
const QMetaObject *meta,
const char *name);
621Q_CORE_EXPORT QDebug qt_QMetaEnum_flagDebugOperator(QDebug &dbg, quint64 value,
const QMetaObject *meta,
const char *name);
625template <
typename Int>
628 static_assert(std::is_unsigned_v<Int>,
629 "Cast value to an unsigned type before calling this function");
630 const QDebugStateSaver saver(debug);
632 debug.nospace() <<
"QFlags(" << Qt::hex << Qt::showbase;
633 bool needSeparator =
false;
634 for (size_t i = 0; i < sizeofT * 8; ++i) {
635 if (value & (Int(1) << i)) {
639 needSeparator =
true;
640 debug << (Int(1) << i);
646template <
class Flags,
647 std::enable_if_t<QtPrivate::IsQFlags<Flags>::value,
bool> =
true>
648inline QDebug operator<<(QDebug debug, Flags flags)
650 using T =
typename Flags::enum_type;
651 using UInt =
typename QIntegerForSizeof<T>::Unsigned;
652#if !defined(QT_NO_QOBJECT)
653 if constexpr (QtPrivate::IsQEnumHelper<T>::Value || QtPrivate::IsQEnumHelper<Flags>::Value) {
656 using Int = std::conditional_t<QtPrivate::IsQEnumHelper<Flags>::Value, UInt,
657 std::underlying_type_t<T>>;
658 const QMetaObject *obj = qt_getEnumMetaObject(T());
659 const char *name = qt_getEnumName(T());
660 return qt_QMetaEnum_flagDebugOperator(debug, Int(flags.toInt()), obj, name);
664 qt_QMetaEnum_flagDebugOperator(debug,
sizeof(T), UInt(flags.toInt()));
671QDebug operator<<(QDebug debug,
const QFlags<T> &flags);
674#if !defined(QT_NO_QOBJECT) && !defined(Q_QDOC)
696std::enable_if_t<QtPrivate::EnumHasQFlag<T>::Value, QDebug>
697operator<<(QDebug debug, T flag)
699 return debug << QFlags(flag);
703std::enable_if_t<QtPrivate::EnumHasQEnum<T>::Value, QDebug>
704operator<<(QDebug dbg, T value)
706 const QMetaObject *obj = qt_getEnumMetaObject(value);
707 const char *name = qt_getEnumName(value);
708 return qt_QMetaEnum_debugOperator(dbg,
static_cast<
typename std::underlying_type<T>::type>(value), obj, name);
714 QDebugStateSaver saver(debug);
715 debug.nospace() <<
"QKeyCombination("
716 << combination.keyboardModifiers()
729#define QT_FOR_EACH_CORE_FOUNDATION_TYPE(F)
740#define QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(F)
744#define QT_FOR_EACH_CORE_GRAPHICS_TYPE(F)
747#define QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(F)
753#define QT_FORWARD_DECLARE_CF_TYPE(type) Q_FORWARD_DECLARE_CF_TYPE(type);
754#define QT_FORWARD_DECLARE_MUTABLE_CF_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CF_TYPE(type);
755#define QT_FORWARD_DECLARE_CG_TYPE(type) Q_FORWARD_DECLARE_CG_TYPE(type);
756#define QT_FORWARD_DECLARE_MUTABLE_CG_TYPE(type) Q_FORWARD_DECLARE_MUTABLE_CG_TYPE(type);
759Q_FORWARD_DECLARE_CF_TYPE(CFString);
761Q_FORWARD_DECLARE_OBJC_CLASS(NSObject);
762QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_CF_TYPE)
763QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_MUTABLE_CF_TYPE)
764QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_CG_TYPE)
765QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_MUTABLE_CG_TYPE)
768#define QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType)
769 Q_CORE_EXPORT QDebug operator
<<(QDebug, CFType##Ref);
771#define Q_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE(CFType)
772 QDebug operator
<<(QDebug debug, CFType##Ref ref)
775 return debug << QT_STRINGIFY(CFType) "Ref(0x0)";
776 if (CFStringRef description = CFCopyDescription(ref)) {
777 QDebugStateSaver saver(debug);
778 debug.noquote() << description;
779 CFRelease(description);
786Q_CORE_EXPORT QDebug operator<<(QDebug, id);
788Q_CORE_EXPORT QDebug operator<<(QDebug, objc_object *);
789Q_CORE_EXPORT QDebug operator<<(QDebug,
const NSObject *);
790Q_CORE_EXPORT QDebug operator<<(QDebug, CFStringRef);
792QT_FOR_EACH_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
793QT_FOR_EACH_MUTABLE_CORE_FOUNDATION_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
794QT_FOR_EACH_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
795QT_FOR_EACH_MUTABLE_CORE_GRAPHICS_TYPE(QT_FORWARD_DECLARE_QDEBUG_OPERATOR_FOR_CF_TYPE)
797#undef QT_FORWARD_DECLARE_CF_TYPE
798#undef QT_FORWARD_DECLARE_MUTABLE_CF_TYPE
799#undef QT_FORWARD_DECLARE_CG_TYPE
800#undef QT_FORWARD_DECLARE_MUTABLE_CG_TYPE
QImageIOHandler * create(QIODevice *device, const QByteArray &format=QByteArray()) const override
Creates and returns a QImageIOHandler subclass, with device and format set.
Combined button and popup list for selecting options.
void qt_QMetaEnum_flagDebugOperator(QDebug &debug, size_t sizeofT, uint value)
QDebug operator<<(QDebug debug, QDir::Filters filters)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
static constexpr bool Value
static constexpr bool Value