Disable output in release mode



  • Hello
    I need to disable console output logs in release mode,
    console.log()

    how i can achieve that
    i tried this , but not worked
    DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT


  • Moderators

    @m.abed

    Are you sure that the output you are still seeing is from qDebug and it different flavors?

    also cout and cerr is shown on the console.



  • Yes , i can see output of console.log and qDebug() in release mode
    i tested on Android and Desktop
    @koahnig



  • Here the solution for my problem

    https://stackoverflow.com/questions/28540571/how-to-enable-and-disable-qdebug-messages?noredirect=1#comment76861982_28540571

    #include <qapplication.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    {
        QByteArray localMsg = msg.toLocal8Bit();
        switch (type) {
        case QtDebugMsg:
            fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtInfoMsg:
            fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtWarningMsg:
            fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtCriticalMsg:
            fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            break;
        case QtFatalMsg:
            fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
            abort();
        }
    }
    
    int main(int argc, char **argv)
    {
        qInstallMessageHandler(myMessageOutput);
        QApplication app(argc, argv);
        ...
        return app.exec();
    }
    

    Thanks Guys



  • @m-abed
    qInstallMessageHandler() is use full for saving the logs to a file, if you don't want to save it to the file than you can use QT_LOGGING_RULES.


Log in to reply
 

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