Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Disable output in release mode

    Mobile and Embedded
    3
    5
    2284
    Loading More Posts
    • 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.
    • M
      m.abed last edited by

      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

      K 1 Reply Last reply Reply Quote 0
      • K
        koahnig @m.abed last edited by koahnig

        @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.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply Reply Quote 0
        • M
          m.abed last edited by m.abed

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

          1 Reply Last reply Reply Quote 0
          • M
            m.abed last edited by

            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

            1 Reply Last reply Reply Quote 1
            • Pradeep P N
              Pradeep P N last edited by

              @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.

              Pradeep Nimbalkar.
              Upvote the answer(s) that helped you to solve the issue...
              Keep code clean.

              1 Reply Last reply Reply Quote 2
              • First post
                Last post