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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • 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 
82 KDECORE_EXPORT QDebug kDebugStream(QtMsgType level, int area, const char *file = 0,
83  int line = -1, const char *funcinfo = 0);
84 
89 KDECORE_EXPORT QDebug kDebugDevNull();
90 
95 KDECORE_EXPORT QString kRealBacktrace(int);
96 
97 
107 #if !defined(KDE_NO_DEBUG_OUTPUT)
108 inline QString kBacktrace(int levels=-1) { return kRealBacktrace(levels); }
109 #else
110 static inline QString kBacktrace(int=-1) { return QString(); }
111 #endif
112 
118 KDECORE_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)
146 
152 static inline QDebug kDebug(int area = KDE_DEFAULT_DEBUG_AREA)
153 { return kDebugStream(QtDebugMsg, area); }
154 static inline QDebug kDebug(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
155 { return cond ? kDebug(area) : kDebugDevNull(); }
156 
157 #else // KDE_NO_DEBUG_OUTPUT
158 static inline QDebug kDebug(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
159 static inline QDebug kDebug(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
160 #endif
161 
162 #if !defined(KDE_NO_WARNING_OUTPUT)
163 
169 static inline QDebug kWarning(int area = KDE_DEFAULT_DEBUG_AREA)
170 { return kDebugStream(QtWarningMsg, area); }
171 static inline QDebug kWarning(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
172 { return cond ? kWarning(area) : kDebugDevNull(); }
173 
174 #else // KDE_NO_WARNING_OUTPUT
175 static inline QDebug kWarning(int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
176 static inline QDebug kWarning(bool, int = KDE_DEFAULT_DEBUG_AREA) { return kDebugDevNull(); }
177 #endif
178 
185 static inline QDebug kError(int area = KDE_DEFAULT_DEBUG_AREA)
186 { return kDebugStream(QtCriticalMsg, area); }
187 static inline QDebug kError(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
188 { return cond ? kError(area) : kDebugDevNull(); }
189 
196 static inline QDebug kFatal(int area = KDE_DEFAULT_DEBUG_AREA)
197 { return kDebugStream(QtFatalMsg, area); }
198 static inline QDebug kFatal(bool cond, int area = KDE_DEFAULT_DEBUG_AREA)
199 { return cond ? kFatal(area) : kDebugDevNull(); }
200 
201 struct KDebugTag { };
202 typedef QDebug (*KDebugStreamFunction)(QDebug, KDebugTag);
203 inline QDebug operator<<(QDebug s, KDebugStreamFunction f)
204 { return (*f)(s, KDebugTag()); }
205 
213 KDECORE_EXPORT QDebug perror(QDebug, KDebugTag);
214 
215 // operators for KDE types
216 class KUrl;
217 class KDateTime;
218 class QObject;
219 KDECORE_EXPORT QDebug operator<<(QDebug s, const KUrl &url);
220 KDECORE_EXPORT QDebug operator<<(QDebug s, const KDateTime &time);
221 
222 #if 1 || defined(KDE3_SUPPORT)
223 #ifndef KDE_NO_DEPRECATED
224 class KDE_DEPRECATED kndbgstream { };
225 typedef QDebug kdbgstream;
226 
227 static inline KDE_DEPRECATED QDebug kdDebug(int area = KDE_DEFAULT_DEBUG_AREA) { return kDebug(area); }
228 static inline KDE_DEPRECATED QDebug kdWarning(int area = KDE_DEFAULT_DEBUG_AREA) { return kWarning(area); }
229 static inline KDE_DEPRECATED QDebug kdError(int area = KDE_DEFAULT_DEBUG_AREA) { return kError(area); }
230 static inline KDE_DEPRECATED QDebug kdFatal(int area = KDE_DEFAULT_DEBUG_AREA) { return kFatal(area); }
231 inline KDE_DEPRECATED QString kdBacktrace(int levels=-1) { return kBacktrace( levels ); }
232 
233 static inline KDE_DEPRECATED QDebug kndDebug() { return kDebugDevNull(); }
234 #endif
235 #endif
236 
237 class WrongSyntax {};
238 
243 class KDebug //krazy= ?
244 {
245  const char *file;
246  const char *funcinfo;
247  int line;
248  QtMsgType level;
249 public:
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 
304 private:
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 
354 class KDECORE_EXPORT KDebug::Block
355 {
356 public:
357  Block(const char* label, int area = KDE_DEFAULT_DEBUG_AREA);
358  ~Block();
359 
360 private:
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 
376 class KDECORE_EXPORT KDebug::Block
377 {
378 public:
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
perror
QDebug perror(QDebug s, KDebugTag)
Definition: kdebug.cpp:779
kDebugDevNull
QDebug kDebugDevNull()
Definition: kdebug.cpp:758
kdecore_export.h
KDebug::hasNullOutput
static bool hasNullOutput(QtMsgType type, bool condition, int area, bool enableByDefault)
Definition: kdebug.cpp:818
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:187
QString
KDebug::KDebug
KDebug(QtMsgType type, const char *f=0, int l=-1, const char *info=0)
Definition: kdebug.h:251
QObject
KUrl
Represents and parses a URL.
Definition: kurl.h:111
KDebug::hasNullOutputQtDebugMsg
static bool hasNullOutputQtDebugMsg(bool condition, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:274
KDebugStreamFunction
QDebug(* KDebugStreamFunction)(QDebug, KDebugTag)
!
Definition: kdebug.h:202
KDebug::Block
Use this to label sections of your code.
Definition: kdebug.h:354
operator<<
QDebug operator<<(QDebug s, KDebugStreamFunction f)
Definition: kdebug.h:203
kClearDebugConfig
void kClearDebugConfig()
Definition: kdebug.cpp:799
KDebug::operator()
QDebug operator()(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:261
KDebug::registerArea
static int registerArea(const QByteArray &areaName, bool enabled=true)
Definition: kdebug.cpp:856
kdBacktrace
QString kdBacktrace(int levels=-1)
Definition: kdebug.h:231
kdFatal
static QDebug kdFatal(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:230
KDebug::hasNullOutputQtDebugMsg
static bool hasNullOutputQtDebugMsg(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:271
KDebug::operator()
QDebug operator()(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:259
KDateTime
A class representing a date and time with an associated time zone.
Definition: kdatetime.h:171
kWarning
#define kWarning
Definition: kdebug.h:322
WrongSyntax
Definition: kdebug.h:237
KDE_DEBUG_ENABLED_BY_DEFAULT
#define KDE_DEBUG_ENABLED_BY_DEFAULT
Definition: kdebug.h:59
kdWarning
static QDebug kdWarning(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:228
kdError
static QDebug kdError(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:229
kdDebug
static QDebug kdDebug(int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:227
KDebug
Definition: kdebug.h:243
KDE_DEFAULT_DEBUG_AREA
#define KDE_DEFAULT_DEBUG_AREA
Definition: kdebug.h:121
kDebugStream
QDebug kDebugStream(QtMsgType level, int area, const char *file=0, int line=-1, const char *funcinfo=0)
Definition: kdebug.cpp:763
KDebug::Block::Block
Block(const char *label, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.cpp:881
kDebug
#define kDebug
Definition: kdebug.h:316
kndbgstream
Definition: kdebug.h:224
kdbgstream
QDebug kdbgstream
Definition: kdebug.h:225
KDebugTag
Definition: kdebug.h:201
kFatal
static QDebug kFatal(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:198
KDebug::Block::~Block
~Block()
Definition: kdebug.cpp:901
kndDebug
static QDebug kndDebug()
Definition: kdebug.h:233
kRealBacktrace
QString kRealBacktrace(int)
Definition: kdebug.cpp:734
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:08 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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