Prevent qDebug function to be compiled in release mode



  • Hi

    I use qDebug in relation with QT_NO_DEBUG_OUTPUT in order to suppress debugging in release mode. In release mode I want this function to not be compiled and not just to be a function that does nothing. I wonder if I need to use a macro in order to be sure that QDebug function will not be compiled at all in release mode? I was thinking of something like below:

    @#ifdef QT_DEBUG
    #define MyDebug qDebug
    #else
    #define MyDebug(fmt, arg...) ((void)0)
    #endif@

    Maybe the practice is somewhat different among Qt community.



  • http://qt-project.org/doc/qt-4.8/qtglobal.html#qDebug

    bq. This function does nothing if QT_NO_DEBUG_OUTPUT was defined during compilation.

    open qdebug.h it returns an empty object.

    @inline QNoDebug qDebug() { return QNoDebug(); }@

    QNoDebug has empty inline functions. there will be no function call overhead...



  • [quote author="WoJo" date="1362672905"]http://qt-project.org/doc/qt-4.8/qtglobal.html#qDebug

    bq. This function does nothing if QT_NO_DEBUG_OUTPUT was defined during compilation.

    open qdebug.h it returns an empty object.

    @inline QNoDebug qDebug() { return QNoDebug(); }@

    QNoDebug has empty inline functions. there will be no function call overhead...[/quote]

    The empty function will probably be removed by the modern compiler, but one cannot be sure for every compiler. I was thinking to use a MACRO to make that certain.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.