Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Indent qdebug output
Forum Updated to NodeBB v4.3 + New Features

Indent qdebug output

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fluca1978
    wrote on last edited by
    #1

    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

    @void MyClass:myMethod(){
    qDebug() << "[BEGIN] myMethod";
    ....
    myOtherClassInstance->myMethod2();
    qDebug() << "[END] myMethod";
    }@

    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:

    @
    [BEGIN] myMethod
    [BEGIN] myMethod2
    [END] myMethod2
    [END] myMethod
    @

    while I'd like something like:

    @
    [BEGIN] myMethod
    [BEGIN] myMethod2
    [END] myMethod2
    [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 Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

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

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SmileOn
        wrote on last edited by SmileOn
        #3

        10 years later I'll just leave it here ...

        QDebug MyClass::qDebug1(int padding_width)
        {
            static QString s("    ");//placeholder
            QDebug ret = qDebug();
            ret.noquote();//optional
            while(padding_width--)
                ret << s;
            return ret;
        }
        

        so

        @void MyClass:myMethod(){
        qDebug1(1) << "[BEGIN] myMethod";
        ....
        myOtherClassInstance->myMethod2();//qDebug1(2);
        qDebug(1) << "[END] myMethod";
        }@
        
            [BEGIN] myMethod
                [BEGIN] myMethod2
                [END] myMethod2
            [END] myMethod
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved