October 24, 2011

fluca1978 fluca1978
Lab Rat
472 posts

indent qdebug output

 

Hi,
this is an awkward question: I’ve got a set of methods that calls each other and I’m using a set of qdebug outputs to follow the method call

  1. void MyClass:myMethod(){
  2.    qDebug() << "[BEGIN] myMethod";
  3. ....
  4.     myOtherClassInstance->myMethod2();
  5.    qDebug() << "[END] myMethod";
  6. }

This works great, but with a lot of methods on the stack it becomes a trouble to follow the stacktrace. Is there a simple and quick way to implement the method calls and the qdebug output? Otherwise, is there any other class that can help me obtaining such result?
Now my output looks like:

  1. [BEGIN] myMethod
  2. [BEGIN] myMethod2
  3. [END] myMethod2
  4. [END] myMethod

while I’d like something like:

  1. [BEGIN] myMethod
  2.   [BEGIN] myMethod2
  3.   [END] myMethod2
  4. [END] myMethod

I guess this is not easily possible in C++ or without using AOP, but maybe Qt provides something like this….
The only solution that comes into my mind is to provide a wrapper around the qDebug that will track and increment the indentation each time I enter a method and will decrease every time I exit.

1 reply

October 24, 2011

Volker Volker
Ant Farmer
5331 posts

The wrapper solution would have been my suggestion too. It doesn’t sound too awkward.

 
  ‹‹ QPainter drawText on a QImage: Wrong text color???!!!      Convert QColor and QSize from and to QString ››

You must log in to post a reply. Not a member yet? Register here!