• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • io
kdebug.h
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
3 2000-2002 Stephan Kulow (coolo@kde.org)
4 2002 Holger Freyther (freyther@kde.org)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef _KDEBUG_H_
23#define _KDEBUG_H_
24
25#include <kdecore_export.h>
26
27#include <QtCore/QDebug>
28#include <QtCore/QElapsedTimer>
29
44#if !defined(KDE_NO_DEBUG_OUTPUT)
45# if defined(QT_NO_DEBUG_OUTPUT) || defined(QT_NO_DEBUG_STREAM)
46# define KDE_NO_DEBUG_OUTPUT
47# endif
48#endif
49
50#if !defined(KDE_NO_WARNING_OUTPUT)
51# if defined(QT_NO_WARNING_OUTPUT)
52# define KDE_NO_WARNING_OUTPUT
53# endif
54#endif
55
56#ifdef QT_NO_DEBUG /* The application is compiled in release mode */
57# define KDE_DEBUG_ENABLED_BY_DEFAULT false
58#else
59# define KDE_DEBUG_ENABLED_BY_DEFAULT true
60#endif
61
67#define k_funcinfo ""
68
76#define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
77
82KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0,
83 int line = -1, const char *funcinfo = 0);
84
89KDECORE_EXPORT QDebug kDebugDevNull();
90
95KDECORE_EXPORT QString kRealBacktrace(int);
96
97
107#if !defined(KDE_NO_DEBUG_OUTPUT)
108inline QString kBacktrace(int levels=-1) { return kRealBacktrace(levels); }
109#else
110static inline QString kBacktrace(int=-1) { return QString(); }
111#endif
112
118KDECORE_EXPORT void kClearDebugConfig();
119
120#ifndef KDE_DEFAULT_DEBUG_AREA
121# define KDE_DEFAULT_DEBUG_AREA 0
122#endif
123
145#if !defined(KDE_NO_DEBUG_OUTPUT)
152static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA)
153{ return kDebugStream(QtDebugMsg, area); }
154static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
155{ return cond ? kDebug(area) : kDebugDevNull(); }
156
157#else // KDE_NO_DEBUG_OUTPUT
158static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
159static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
160#endif
161
162#if !defined(KDE_NO_WARNING_OUTPUT)
169static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA)
170{ return kDebugStream(QtWarningMsg, area); }
171static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
172{ return cond ? kWarning(area) : kDebugDevNull(); }
173
174#else // KDE_NO_WARNING_OUTPUT
175static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
176static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
177#endif
178
185static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA)
186{ return kDebugStream(QtCriticalMsg, area); }
187static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
188{ return cond ? kError(area) : kDebugDevNull(); }
189
196static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA)
197{ return kDebugStream(QtFatalMsg, area); }
198static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
199{ return cond ? kFatal(area) : kDebugDevNull(); }
200
201struct KDebugTag { };
202typedef QDebug (*KDebugStreamFunction)(QDebug, KDebugTag);
203inline QDebug operator<<(QDebug s, KDebugStreamFunction f)
204{ return (*f)(s, KDebugTag()); }
205
213KDECORE_EXPORT QDebug perror(QDebug, KDebugTag);
214
215// operators for KDE types
216class KUrl;
217class KDateTime;
218class QObject;
219KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url);
220KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time);
221
222#if 1 || defined(KDE3_SUPPORT)
223#ifndef KDE_NO_DEPRECATED
224class KDE_DEPRECATED kndbgstream { };
225typedef QDebug kdbgstream;
226
227static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); }
228static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); }
229static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); }
230static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); }
231inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); }
232
233static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); }
234#endif
235#endif
236
237class WrongSyntax {};
238
243class KDebug //krazy= ?
244{
245 const char *file;
246 const char *funcinfo;
247 int line;
248 QtMsgType level;
249public:
250 class Block;
251 explicit inline KDebug(QtMsgType type, const char *f = 0, int l = -1, const char *info = 0)
252 : file(f), funcinfo(info), line(l), level(type)
253 {
254#ifdef KDE4_CMAKE_TOPLEVEL_DIR_LENGTH // set by FindKDE4Internal.cmake
255 file = file + KDE4_CMAKE_TOPLEVEL_DIR_LENGTH + 1;
256#endif
257 }
258
259 inline QDebug operator()(int area = KDE_DEFAULT_DEBUG_AREA)
260 { return kDebugStream(level, area, file, line, funcinfo); }
261 inline QDebug operator()(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
262 { if (cond) return operator()(area); return kDebugDevNull(); }
263
265 static KDECORE_EXPORT bool hasNullOutput(QtMsgType type,
266 bool condition,
267 int area,
268 bool enableByDefault);
269
271 static inline bool hasNullOutputQtDebugMsg(int area = KDE_DEFAULT_DEBUG_AREA)
272 { return hasNullOutput(QtDebugMsg, true, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
274 static inline bool hasNullOutputQtDebugMsg(bool condition, int area = KDE_DEFAULT_DEBUG_AREA)
275 { return hasNullOutput(QtDebugMsg, condition, area, KDE_DEBUG_ENABLED_BY_DEFAULT); }
276
302 static KDECORE_EXPORT int registerArea(const QByteArray& areaName, bool enabled = true);
303
304private:
305 WrongSyntax operator()(const char*) {return WrongSyntax();} // error! Use kDebug() << "..." or kWarning() << "..." instead.
306};
307
308
309#if !defined(KDE_NO_DEBUG_OUTPUT)
310/* __VA_ARGS__ should work with any supported GCC version and MSVC > 2005 */
311# if defined(Q_CC_GNU) || (defined(Q_CC_MSVC) && _MSC_VER >= 1500)
312# define kDebug(...) for (bool _k_kDebugDoOutput_ = !KDebug::hasNullOutputQtDebugMsg(__VA_ARGS__); \
313 KDE_ISUNLIKELY(_k_kDebugDoOutput_); _k_kDebugDoOutput_ = false) \
314 KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)(__VA_ARGS__)
315# else
316# define kDebug KDebug(QtDebugMsg, __FILE__, __LINE__, Q_FUNC_INFO)
317# endif
318#else
319# define kDebug while (false) kDebug
320#endif
321#if !defined(KDE_NO_WARNING_OUTPUT)
322# define kWarning KDebug(QtWarningMsg, __FILE__, __LINE__, Q_FUNC_INFO)
323#else
324# define kWarning while (false) kWarning
325#endif
326
327#ifndef KDE_NO_DEBUG_OUTPUT
328
354class KDECORE_EXPORT KDebug::Block
355{
356public:
357 Block(const char* label, int area = KDE_DEFAULT_DEBUG_AREA);
358 ~Block();
359
360private:
361 QElapsedTimer m_startTime;
362 const char *m_label; // KDE5 TODO: REMOVE
363 int m_area;
364 int m_color;
365 class Private;
366 Private* d;
367};
368
372#define KDEBUG_BLOCK KDebug::Block _kDebugBlock(Q_FUNC_INFO);
373
374#else
375
376class KDECORE_EXPORT KDebug::Block
377{
378public:
379 Block(const char*, int = KDE_DEFAULT_DEBUG_AREA) {}
380 ~Block() {}
381};
382
383#define KDEBUG_BLOCK
384
385#endif
386
392#define KWARNING_NOTIMPLEMENTED kWarning() << "NOT-IMPLEMENTED";
393
399#define KWARNING_DEPRECATED kWarning() << "DEPRECATED";
400
403#endif
KDateTime
A class representing a date and time with an associated time zone.
Definition: kdatetime.h:172
KDebug::Block
Use this to label sections of your code.
Definition: kdebug.h:355
KDebug::Block::~Block
~Block()
Definition: kdebug.cpp:901
KDebug
Definition: kdebug.h:244
KDebug::hasNullOutput
static bool hasNullOutput(QtMsgType type, bool condition, int area, bool enableByDefault)
Definition: kdebug.cpp:818
KDebug::operator()
QDebug operator()(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:259
KDebug::operator()
QDebug operator()(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:261
KDebug::hasNullOutputQtDebugMsg
static bool hasNullOutputQtDebugMsg(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:271
KDebug::KDebug
KDebug(QtMsgType type, const char *f=0, int l=-1, const char *info=0)
Definition: kdebug.h:251
KDebug::hasNullOutputQtDebugMsg
static bool hasNullOutputQtDebugMsg(bool condition, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:274
KUrl
Represents and parses a URL.
Definition: kurl.h:112
QObject
QString
WrongSyntax
Definition: kdebug.h:237
kndbgstream
Definition: kdebug.h:224
kdWarning
static QDebug kdWarning(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:228
KDE_DEBUG_ENABLED_BY_DEFAULT
#define KDE_DEBUG_ENABLED_BY_DEFAULT
Definition: kdebug.h:59
KDebugStreamFunction
QDebug(* KDebugStreamFunction)(QDebug, KDebugTag)
!
Definition: kdebug.h:202
kDebugStream
QDebug kDebugStream(QtMsgType level, int area, const char *file=0, int line=-1, const char *funcinfo=0)
Definition: kdebug.cpp:763
kdBacktrace
QString kdBacktrace(int levels=-1)
Definition: kdebug.h:231
kdbgstream
QDebug kdbgstream
Definition: kdebug.h:225
kFatal
static QDebug kFatal(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:198
kRealBacktrace
QString kRealBacktrace(int)
Definition: kdebug.cpp:734
operator<<
QDebug operator<<(QDebug s, KDebugStreamFunction f)
Definition: kdebug.h:203
kdDebug
static QDebug kdDebug(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:227
kdFatal
static QDebug kdFatal(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:230
kDebug
#define kDebug
Definition: kdebug.h:316
kndDebug
static QDebug kndDebug()
Definition: kdebug.h:233
kDebugDevNull
QDebug kDebugDevNull()
Definition: kdebug.cpp:758
kWarning
#define kWarning
Definition: kdebug.h:322
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:187
KDE_DEFAULT_DEBUG_AREA
#define KDE_DEFAULT_DEBUG_AREA
Definition: kdebug.h:121
kdError
static QDebug kdError(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:229
perror
QDebug perror(QDebug s, KDebugTag)
Definition: kdebug.cpp:779
kClearDebugConfig
void kClearDebugConfig()
Definition: kdebug.cpp:799
kdecore_export.h
KDebugTag
Definition: kdebug.h:201
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal