tags:

views:

43

answers:

2

I'm developing a Qt application. For each class, I'm trying to mimic the framework, such as error() and errorString() method, use of Private implementation.

But I would like to add a per class debugging:

  • Set a macro to the desired level of debug,
  • have a macro or a function that knows the level of debug, and use qDebug() or qWarning() which is class independant, and will know the current class's name (for some pretty prints)

Anyone have a good idea to implement this ?

A: 

Hi.

You may write a class, for example CDebug with all needed debug methods, and use it in other classes, like:

class CMyDialog : public QDialog, public CDebug {...};
mosg
That's an interesting point. So I could implement a set of methods: setDebugLevel(), debug(int level), warn(int level)
dzen
@dzen Yes. I used on my previous project such a practice...
mosg
+1  A: 

Maybe the QxtLogger class, part of the Qxt library (an extension library for Qt) provides what you need.

I would definitely consider using something already existing and tested rather than implementing my own logging solution.

Jérôme
+1 - grab something _off of the shelf_ for logging. I would recommend reading through the source. It is a good learning experience.
D.Shawley