Results 1 to 3 of 3

Thread: qDebug macro substitution

  1. #1
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question qDebug macro substitution

    I want to create a macro that expands to qDebug, so I suppress the qDebug output in release build.
    How can I do it correctly?

    I tried with:

    Qt Code:
    1. #ifdef MY_DEBUG
    2. #define QDEBUG(x) qDebug(x)
    3. #else
    4. #define QDEBUG(x)
    5. #endif
    To copy to clipboard, switch view to plain text mode 

    but I have a problem with multiple qDebug parameters like:

    Qt Code:
    1. qDebug ( "ENTER in DeviceConfiguration = %s\n", moduleName.ascii() );
    To copy to clipboard, switch view to plain text mode 

    Any help?
    Thanks,
    the_bis

  2. #2
    Join Date
    Jan 2006
    Posts
    39
    Thanks
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qDebug macro substitution

    This works for me (using TRACE instead of QDEBUG, of course):
    Qt Code:
    1. #ifdef DEBUG
    2. #define TRACE qDebug
    3. #else
    4. #define TRACE(fmt,arg...) ((void)0)
    5. #endif
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Sep 2006
    Posts
    27
    Thanks
    4
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Thumbs up Re: qDebug macro substitution

    Yes! It works!

    My project.pro is now:

    Qt Code:
    1. [...]
    2. CONFIG += qt warn_on debug
    3. [...]
    4. debug {
    5. DEFINES += MY_DEBUG
    6. }
    7. [...]
    To copy to clipboard, switch view to plain text mode 

    and my project.cpp is now:

    Qt Code:
    1. #ifdef MY_DEBUG
    2. #define QDEBUG qDebug
    3. #else
    4. #define QDEBUG(fmt,arg...) ((void)0)
    5. #endif
    6. [...]
    7. QDEBUG ( "Value now is %s\n", varResult.ascii() );
    8. [...]
    To copy to clipboard, switch view to plain text mode 

    Thank you very much,
    the_bis

Similar Threads

  1. qDebug() under Windows
    By jlbrd in forum Qt Programming
    Replies: 10
    Last Post: 20th March 2007, 07:10
  2. Disable qDebug output
    By the_bis in forum Qt Programming
    Replies: 7
    Last Post: 30th November 2006, 20:14
  3. qDebug() output
    By Doug Broadwell in forum Newbie
    Replies: 1
    Last Post: 1st November 2006, 21:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.