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. Create Logging file Using Qfile
Forum Update on Monday, May 27th 2025

Create Logging file Using Qfile

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 3.1k Views
  • 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 Offline
    M Offline
    Mc6bullet
    wrote on last edited by
    #1

    Hello,
    actually i created one file in that i want to save all the application output of qt?
    anyone have idea how to create that file
    please help me?

    jsulmJ CP71C 2 Replies Last reply
    0
    • M Mc6bullet

      Hello,
      actually i created one file in that i want to save all the application output of qt?
      anyone have idea how to create that file
      please help me?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mc6bullet said in Create Logging file Using Qfile:

      all the application output

      What exact output do you mean? std::cout? qDebug()? Something else?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Mc6bullet said in Create Logging file Using Qfile:

        all the application output

        What exact output do you mean? std::cout? qDebug()? Something else?

        M Offline
        M Offline
        Mc6bullet
        wrote on last edited by
        #3

        @jsulm Means whole console of the QT save in the .log file
        example api requests etc.

        jsulmJ J.HilkJ 2 Replies Last reply
        0
        • M Mc6bullet

          @jsulm Means whole console of the QT save in the .log file
          example api requests etc.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @Mc6bullet said in Create Logging file Using Qfile:

          Means whole console of the QT

          What is Qt console? It is still not really clear what you mean.
          I guess you want to write everything printed to stdout in a file?
          There are different ways.
          Simplest solution is to forward the stdout output to a file:

          ./name_of_your_exe > log.txt
          

          Or, you can do it internally in your app, see https://stackoverflow.com/questions/9211298/redirect-stdcout-to-qtextedit/45507241 for inspiration.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          5
          • M Mc6bullet

            @jsulm Means whole console of the QT save in the .log file
            example api requests etc.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Mc6bullet additionally to what @jsulm said, there's also

            https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler

            that would allow you to redirect everything to a file


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            5
            • M Mc6bullet

              Hello,
              actually i created one file in that i want to save all the application output of qt?
              anyone have idea how to create that file
              please help me?

              CP71C Offline
              CP71C Offline
              CP71
              wrote on last edited by
              #6

              @Mc6bullet
              Hi,
              if you have several qDebug() that help you for diagnostic, you can introduce the following code:

              in main.cpp

              ////////////////////////////////////////////////////////////////////////////////////////////
              ///
              void myMessageOutput(QtMsgType type, const char *msg)
              {
              ...
              // Here we can send text in the fileLog and/or console via application configuration
              switch (type) {
              case QtDebugMsg:
              ...
              break;
              case QtWarningMsg:
              ...
              break;
              case QtCriticalMsg:
              ....
              break;
              case QtFatalMsg:
              if ( errConsoleEnable ) fprintf(stderr, "Fatal: %s\r\n", msg);
              abort();
              }

              if(errLogEnable) {
                  outErrLog->write(text.toLatin1(), text.length());
                  outErrLog->flush();
              }
              

              }

              in int main(int argc, char *argv[])
              {
              ...
              outErrLog = new QFile(F_GET_FILE_LOG);
              outErrLog->open( QIODevice::WriteOnly | QIODevice::Append );

              qInstallMsgHandler(myMessageOutput);
              ...
              

              }

              outErrLog is QFile created once at startup
              Be careful, above is Qt4 code, I think in Qt5 the called qInstallMsgHandler is obsolete, but you have to check.

              Another way is creating a log manager where you can store messages wherever you want (txt, csv, sql and so on). For me, for this object, I think is a good way a single instance object

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mc6bullet
                wrote on last edited by
                #7

                Thank you so much @CP71 @J-Hilk @jsulm You help me lot

                1 Reply Last reply
                1

                • Login

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