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. The Logs are not showing in Application Window.
Qt 6.11 is out! See what's new in the release blog

The Logs are not showing in Application Window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 3 Posters 3.8k 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.
  • Aviral 0A Offline
    Aviral 0A Offline
    Aviral 0
    wrote on last edited by Aviral 0
    #1

    Hi, i am making a Tail Log application. It is executing perfectly but the output window is not showing any results.
    Below is the code:
    LogTail.cpp

    #include "logtail.h"
    #include <QApplication>
    #include <QTextEdit>
    #include<QDebug>
    //start id=constructor
    LogTail::LogTail(QString fn) {
        //if (fn == QString()) {
        //    fn = "C:/Users/arpit.k/OneDrive - Accord Software & Systems Pvt. Ltd/Documents/QT/LogTail3/sample.log";
       // }
        connect (this, SIGNAL(readyReadStandardOutput()),
            this, SLOT(logOutput()));       /* When there is input ready, call this slot.*/
        QStringList argv;
    
        argv << "-f" << fn;                 /* tail -f filename */
        start("tail", argv);                /* Returns immediately, and now there is a child process running, "attached"
        to this process. When this process exits, the child tail process will also terminate. */
    }
    LogTail::~LogTail() {
        terminate();                        /* Attempts to terminate this process. */
    }
    //end
    
    //start id=logOutput
    // tail sends its output to stdout.
    void LogTail::logOutput() {             /* Slot called whenever there is input to read. */
        QByteArray bytes = readAllStandardOutput();
        QStringList lines = QString(bytes).split("\n");
        foreach (QString line, lines) {
            //qDebug() << line;
            emit logString(line);
        }
    }
    //end
    

    main.cpp

    #include "logtail.h"
    #include <QTextEdit>
    #include <QApplication>
    
    int main (int argc, char* argv[]) {
        QApplication app(argc, argv);
        QStringList al = app.arguments();
        QTextEdit textEdit;
        textEdit.setWindowTitle("Debug");
        textEdit.setWindowTitle("logtail demo");
        QString filename = "sample.log";
        if (al.size() > 1) filename = al[1];
        LogTail tail(filename);             /* Create object, starts process too. */
        tail.connect (&tail, SIGNAL(logString(const QString&)),
            &textEdit, SLOT(append(const QString&)));
        textEdit.show();
        return app.exec();
    }
    
    

    Screenshot 2023-02-09 101847.png

    Note: sample.log file contains log data

    jsulmJ 1 Reply Last reply
    0
    • Aviral 0A Aviral 0

      Hi, i am making a Tail Log application. It is executing perfectly but the output window is not showing any results.
      Below is the code:
      LogTail.cpp

      #include "logtail.h"
      #include <QApplication>
      #include <QTextEdit>
      #include<QDebug>
      //start id=constructor
      LogTail::LogTail(QString fn) {
          //if (fn == QString()) {
          //    fn = "C:/Users/arpit.k/OneDrive - Accord Software & Systems Pvt. Ltd/Documents/QT/LogTail3/sample.log";
         // }
          connect (this, SIGNAL(readyReadStandardOutput()),
              this, SLOT(logOutput()));       /* When there is input ready, call this slot.*/
          QStringList argv;
      
          argv << "-f" << fn;                 /* tail -f filename */
          start("tail", argv);                /* Returns immediately, and now there is a child process running, "attached"
          to this process. When this process exits, the child tail process will also terminate. */
      }
      LogTail::~LogTail() {
          terminate();                        /* Attempts to terminate this process. */
      }
      //end
      
      //start id=logOutput
      // tail sends its output to stdout.
      void LogTail::logOutput() {             /* Slot called whenever there is input to read. */
          QByteArray bytes = readAllStandardOutput();
          QStringList lines = QString(bytes).split("\n");
          foreach (QString line, lines) {
              //qDebug() << line;
              emit logString(line);
          }
      }
      //end
      

      main.cpp

      #include "logtail.h"
      #include <QTextEdit>
      #include <QApplication>
      
      int main (int argc, char* argv[]) {
          QApplication app(argc, argv);
          QStringList al = app.arguments();
          QTextEdit textEdit;
          textEdit.setWindowTitle("Debug");
          textEdit.setWindowTitle("logtail demo");
          QString filename = "sample.log";
          if (al.size() > 1) filename = al[1];
          LogTail tail(filename);             /* Create object, starts process too. */
          tail.connect (&tail, SIGNAL(logString(const QString&)),
              &textEdit, SLOT(append(const QString&)));
          textEdit.show();
          return app.exec();
      }
      
      

      Screenshot 2023-02-09 101847.png

      Note: sample.log file contains log data

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

      @Aviral-0 How should this work at all? Who is emitting readyReadStandardOutput() signal?
      Why don't you use QProcess to run the command?

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

      Aviral 0A 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Aviral-0 How should this work at all? Who is emitting readyReadStandardOutput() signal?
        Why don't you use QProcess to run the command?

        Aviral 0A Offline
        Aviral 0A Offline
        Aviral 0
        wrote on last edited by
        #3

        @jsulm If I am using this, then its not able to detect the file and doesn't display anything:

        #include <QApplication>
        #include <QFile>
        #include <QPlainTextEdit>
        #include <QProcess>
        #include <QTextStream>
        #include <QTimer>
        
        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
        
            QPlainTextEdit *textEdit = new QPlainTextEdit;
            textEdit->setReadOnly(true);
            textEdit->show();
        
            QProcess *process = new QProcess;
            process->start("tail", QStringList() << "-n" << "10" << "log.txt");
            process->waitForStarted();
            textEdit->setPlainText(QString(process->readAll()));
        
            QTimer *timer = new QTimer;
            QObject::connect(timer, &QTimer::timeout, [textEdit, process] {
                process->start("tail", QStringList() << "-n" << "10" << "log.txt");
                process->waitForFinished();
                textEdit->setPlainText(QString(process->readAll()));
            });
            timer->start(1000);
        
            return a.exec();
        }
        
        

        What I am getting wrong?

        jsulmJ 1 Reply Last reply
        0
        • Aviral 0A Aviral 0

          @jsulm If I am using this, then its not able to detect the file and doesn't display anything:

          #include <QApplication>
          #include <QFile>
          #include <QPlainTextEdit>
          #include <QProcess>
          #include <QTextStream>
          #include <QTimer>
          
          int main(int argc, char *argv[])
          {
              QApplication a(argc, argv);
          
              QPlainTextEdit *textEdit = new QPlainTextEdit;
              textEdit->setReadOnly(true);
              textEdit->show();
          
              QProcess *process = new QProcess;
              process->start("tail", QStringList() << "-n" << "10" << "log.txt");
              process->waitForStarted();
              textEdit->setPlainText(QString(process->readAll()));
          
              QTimer *timer = new QTimer;
              QObject::connect(timer, &QTimer::timeout, [textEdit, process] {
                  process->start("tail", QStringList() << "-n" << "10" << "log.txt");
                  process->waitForFinished();
                  textEdit->setPlainText(QString(process->readAll()));
              });
              timer->start(1000);
          
              return a.exec();
          }
          
          

          What I am getting wrong?

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

          @Aviral-0 said in The Logs are not showing in Application Window.:

          What I am getting wrong?

          You're not using https://doc.qt.io/qt-6/qprocess.html#readyReadStandardOutput from QProcess to execute a slot everytime there is something to read from the process. So connect a slot to that signal and read the output of the process using https://doc.qt.io/qt-6/qprocess.html#readAllStandardOutput

          Also, you have zero error handling! Please add it (see https://doc.qt.io/qt-6/qprocess.html#errorOccurred and https://doc.qt.io/qt-6/qprocess.html#error).

          Another thing to consider: you're using relative path to the log file - if the file is not inside the working directory tail will not find it...

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

          Aviral 0A 1 Reply Last reply
          1
          • jsulmJ jsulm

            @Aviral-0 said in The Logs are not showing in Application Window.:

            What I am getting wrong?

            You're not using https://doc.qt.io/qt-6/qprocess.html#readyReadStandardOutput from QProcess to execute a slot everytime there is something to read from the process. So connect a slot to that signal and read the output of the process using https://doc.qt.io/qt-6/qprocess.html#readAllStandardOutput

            Also, you have zero error handling! Please add it (see https://doc.qt.io/qt-6/qprocess.html#errorOccurred and https://doc.qt.io/qt-6/qprocess.html#error).

            Another thing to consider: you're using relative path to the log file - if the file is not inside the working directory tail will not find it...

            Aviral 0A Offline
            Aviral 0A Offline
            Aviral 0
            wrote on last edited by
            #5

            @jsulm Please can you write me the code of readyReadStandardOutput
            As I am very new to QT. I would really appreciate your efforts.
            Also with file path: I have given absolute file path and also put the file in the code folder. still its not detecting

            jsulmJ 1 Reply Last reply
            0
            • Aviral 0A Aviral 0

              @jsulm Please can you write me the code of readyReadStandardOutput
              As I am very new to QT. I would really appreciate your efforts.
              Also with file path: I have given absolute file path and also put the file in the code folder. still its not detecting

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

              @Aviral-0 You should know how to connect a slot to a signal, so please at least try to write the code by yourself...

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

              Aviral 0A 1 Reply Last reply
              0
              • jsulmJ jsulm

                @Aviral-0 You should know how to connect a slot to a signal, so please at least try to write the code by yourself...

                Aviral 0A Offline
                Aviral 0A Offline
                Aviral 0
                wrote on last edited by
                #7

                @jsulm Hi, I have tried this:

                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                
                    QPlainTextEdit *textEdit = new QPlainTextEdit;
                    textEdit->setReadOnly(true);
                    textEdit->show();
                
                    QProcess *process = new QProcess;
                    process->start("tail", QStringList() << "-n" << "10" << "../logs/sample.log");
                    process->waitForStarted();
                    QObject::connect(process, &QProcess::readyReadStandardOutput, [textEdit, process] {
                            textEdit->appendPlainText(QString(process->readAllStandardOutput()));
                        });
                    textEdit->setPlainText(QString(process->readAll()));
                
                    QTimer *timer = new QTimer;
                    QObject::connect(timer, &QTimer::timeout, [textEdit, process] {
                        process->start("tail", QStringList() << "-n" << "10" << "../logs/sample.log");
                        process->waitForFinished();
                        textEdit->setPlainText(QString(process->readAll()));
                    });
                    timer->start(1000);
                
                    return a.exec();
                }
                

                Still not getting results. :(

                jsulmJ 1 Reply Last reply
                0
                • Aviral 0A Aviral 0

                  @jsulm Hi, I have tried this:

                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                  
                      QPlainTextEdit *textEdit = new QPlainTextEdit;
                      textEdit->setReadOnly(true);
                      textEdit->show();
                  
                      QProcess *process = new QProcess;
                      process->start("tail", QStringList() << "-n" << "10" << "../logs/sample.log");
                      process->waitForStarted();
                      QObject::connect(process, &QProcess::readyReadStandardOutput, [textEdit, process] {
                              textEdit->appendPlainText(QString(process->readAllStandardOutput()));
                          });
                      textEdit->setPlainText(QString(process->readAll()));
                  
                      QTimer *timer = new QTimer;
                      QObject::connect(timer, &QTimer::timeout, [textEdit, process] {
                          process->start("tail", QStringList() << "-n" << "10" << "../logs/sample.log");
                          process->waitForFinished();
                          textEdit->setPlainText(QString(process->readAll()));
                      });
                      timer->start(1000);
                  
                      return a.exec();
                  }
                  

                  Still not getting results. :(

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

                  @Aviral-0 I repeat myself: add error handling and make sure the path to log file is correct and can be found by tail at runtime...
                  I would also do the connect before calling waitForStarted (which is actually not needed if using signals/slots).
                  There is also no need for a timer to detect termination of a process, there is https://doc.qt.io/qt-6/qprocess.html#finished for that.

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

                  Aviral 0A 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Aviral-0 I repeat myself: add error handling and make sure the path to log file is correct and can be found by tail at runtime...
                    I would also do the connect before calling waitForStarted (which is actually not needed if using signals/slots).
                    There is also no need for a timer to detect termination of a process, there is https://doc.qt.io/qt-6/qprocess.html#finished for that.

                    Aviral 0A Offline
                    Aviral 0A Offline
                    Aviral 0
                    wrote on last edited by Aviral 0
                    #9

                    @jsulm Hi, This is the updated one:
                    And still not able to read file:

                    #include <QApplication>
                    #include <QDebug>
                    #include <QFile>
                    #include <QPlainTextEdit>
                    #include <QProcess>
                    #include <QTextStream>
                    #include <QTimer>
                    
                    int main(int argc, char *argv[])
                    {
                        QApplication a(argc, argv);
                    
                        QPlainTextEdit *textEdit = new QPlainTextEdit;
                        textEdit->setReadOnly(true);
                        textEdit->show();
                    
                        QProcess *process = new QProcess;
                        process->start("tail", QStringList() << "-n" << "10" << "sample.log");
                    
                        QObject::connect(process, &QProcess::readyReadStandardOutput, [textEdit, process] {
                            textEdit->setPlainText(QString(process->readAllStandardOutput()));
                        });
                        QObject::connect(process, &QProcess::errorOccurred, [](QProcess::ProcessError error) {
                            qWarning() << "Error occurred:" << error;
                        });
                        QObject::connect(process, &QProcess::finished, [process](int exitCode, QProcess::ExitStatus exitStatus) {
                            if (exitStatus == QProcess::CrashExit) {
                                qWarning() << "Process crashed with code" << exitCode;
                            } else {
                                qDebug() << "Process finished with code" << exitCode;
                            }
                    
                            process->start("tail", QStringList() << "-n" << "10" << "sample.log");
                        });
                    
                        return a.exec();
                    }
                    

                    I have put the copy of file in built folder, source folder and everywhere but still its not able to read.
                    Also after putting absolute path of the file, still not worked!

                    jsulmJ 1 Reply Last reply
                    0
                    • Aviral 0A Aviral 0

                      @jsulm Hi, This is the updated one:
                      And still not able to read file:

                      #include <QApplication>
                      #include <QDebug>
                      #include <QFile>
                      #include <QPlainTextEdit>
                      #include <QProcess>
                      #include <QTextStream>
                      #include <QTimer>
                      
                      int main(int argc, char *argv[])
                      {
                          QApplication a(argc, argv);
                      
                          QPlainTextEdit *textEdit = new QPlainTextEdit;
                          textEdit->setReadOnly(true);
                          textEdit->show();
                      
                          QProcess *process = new QProcess;
                          process->start("tail", QStringList() << "-n" << "10" << "sample.log");
                      
                          QObject::connect(process, &QProcess::readyReadStandardOutput, [textEdit, process] {
                              textEdit->setPlainText(QString(process->readAllStandardOutput()));
                          });
                          QObject::connect(process, &QProcess::errorOccurred, [](QProcess::ProcessError error) {
                              qWarning() << "Error occurred:" << error;
                          });
                          QObject::connect(process, &QProcess::finished, [process](int exitCode, QProcess::ExitStatus exitStatus) {
                              if (exitStatus == QProcess::CrashExit) {
                                  qWarning() << "Process crashed with code" << exitCode;
                              } else {
                                  qDebug() << "Process finished with code" << exitCode;
                              }
                      
                              process->start("tail", QStringList() << "-n" << "10" << "sample.log");
                          });
                      
                          return a.exec();
                      }
                      

                      I have put the copy of file in built folder, source folder and everywhere but still its not able to read.
                      Also after putting absolute path of the file, still not worked!

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

                      @Aviral-0 said in The Logs are not showing in Application Window.:

                      I have put the copy of file in built folder, source folder and everywhere but still its not able to read

                      Why don't you simply use an absolute path for testing?
                      Was errorOccurred signal emitted?

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

                      Aviral 0A 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @Aviral-0 said in The Logs are not showing in Application Window.:

                        I have put the copy of file in built folder, source folder and everywhere but still its not able to read

                        Why don't you simply use an absolute path for testing?
                        Was errorOccurred signal emitted?

                        Aviral 0A Offline
                        Aviral 0A Offline
                        Aviral 0
                        wrote on last edited by
                        #11

                        @jsulm I have used absolute path and it is not working and also no error was generated

                        jsulmJ JonBJ 2 Replies Last reply
                        0
                        • Aviral 0A Aviral 0

                          @jsulm I have used absolute path and it is not working and also no error was generated

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

                          @Aviral-0 Could be that tail prints out an error on stderr. To check that connect a slot to https://doc.qt.io/qt-6/qprocess.html#readyReadStandardError and print out what https://doc.qt.io/qt-6/qprocess.html#readAllStandardError returns there.

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

                          1 Reply Last reply
                          0
                          • Aviral 0A Aviral 0

                            @jsulm I have used absolute path and it is not working and also no error was generated

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @Aviral-0
                            We have said this before, but one more time. You are not doing yourself any favors by doing this via QProcess & tail command. @jsulm wrote in https://forum.qt.io/topic/142476/how-to-display-recent-logs-and-can-be-filter-according-to-the-checkboxes/12

                            @Aviral-0 You can open the file, seek to file end and then connect a slot to https://doc.qt.io/qt-6/qfilesystemwatcher.html#fileChanged signal. In the slot you simply read to the end of the file and add the data you read to your log widget.

                            Or just use a QTimer instead of QFileSystemWatcher, which may well be what tail -f does. Up to you, just saying.

                            Actually, I now see that for this question you are only using tail -n not tail -f. Which makes it even easier to do this by reading the file in your process.

                            Aviral 0A 1 Reply Last reply
                            1
                            • JonBJ JonB

                              @Aviral-0
                              We have said this before, but one more time. You are not doing yourself any favors by doing this via QProcess & tail command. @jsulm wrote in https://forum.qt.io/topic/142476/how-to-display-recent-logs-and-can-be-filter-according-to-the-checkboxes/12

                              @Aviral-0 You can open the file, seek to file end and then connect a slot to https://doc.qt.io/qt-6/qfilesystemwatcher.html#fileChanged signal. In the slot you simply read to the end of the file and add the data you read to your log widget.

                              Or just use a QTimer instead of QFileSystemWatcher, which may well be what tail -f does. Up to you, just saying.

                              Actually, I now see that for this question you are only using tail -n not tail -f. Which makes it even easier to do this by reading the file in your process.

                              Aviral 0A Offline
                              Aviral 0A Offline
                              Aviral 0
                              wrote on last edited by
                              #14

                              @JonB I was using QTimer, but @jsulm suggested my not to https://forum.qt.io/post/746836
                              Also I replaced tail -n with tail -f and its not working. I am really confused what is not working.

                              jsulmJ JonBJ 2 Replies Last reply
                              0
                              • Aviral 0A Aviral 0

                                @JonB I was using QTimer, but @jsulm suggested my not to https://forum.qt.io/post/746836
                                Also I replaced tail -n with tail -f and its not working. I am really confused what is not working.

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

                                @Aviral-0 said in The Logs are not showing in Application Window.:

                                I was using QTimer, but @jsulm suggested my not to https://forum.qt.io/post/746836

                                Sorry, but this is just wrong!
                                I suggested not to use QTimer to detect when the process finishes.
                                @JonB is talking about something completelly different (not using QProcess). Please read more carefully!

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

                                1 Reply Last reply
                                1
                                • Aviral 0A Aviral 0

                                  @JonB I was using QTimer, but @jsulm suggested my not to https://forum.qt.io/post/746836
                                  Also I replaced tail -n with tail -f and its not working. I am really confused what is not working.

                                  JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by
                                  #16

                                  @Aviral-0
                                  No he did not. He said you don't need a QTimer for

                                  There is also no need for a timer to detect termination of a process, there is https://doc.qt.io/qt-6/qprocess.html#finished for that.

                                  That is detecting a program finishes, not for picking up the tail of some output.

                                  Also I replaced tail -n with tail -f and its not working. I am really confused what is not working

                                  Why are you attempting to run an external process to print out the last lines in some log file when you could do it yourself in your app by reading the file? I have said before: you can do it via QProcess/tail if you really want to, but since you are having problems with that maybe it would be simpler not to do it that way.

                                  Aviral 0A 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @Aviral-0
                                    No he did not. He said you don't need a QTimer for

                                    There is also no need for a timer to detect termination of a process, there is https://doc.qt.io/qt-6/qprocess.html#finished for that.

                                    That is detecting a program finishes, not for picking up the tail of some output.

                                    Also I replaced tail -n with tail -f and its not working. I am really confused what is not working

                                    Why are you attempting to run an external process to print out the last lines in some log file when you could do it yourself in your app by reading the file? I have said before: you can do it via QProcess/tail if you really want to, but since you are having problems with that maybe it would be simpler not to do it that way.

                                    Aviral 0A Offline
                                    Aviral 0A Offline
                                    Aviral 0
                                    wrote on last edited by
                                    #17

                                    @JonB @jsulm I know it would be frustrating for you both. But Can anyone please write in simple technical terms of what functions I have to use. In a process execution manner?

                                    jsulmJ JonBJ 2 Replies Last reply
                                    0
                                    • Aviral 0A Aviral 0

                                      @JonB @jsulm I know it would be frustrating for you both. But Can anyone please write in simple technical terms of what functions I have to use. In a process execution manner?

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

                                      @Aviral-0 said in The Logs are not showing in Application Window.:

                                      But Can anyone please write in simple technical terms of what functions

                                      Please first clarify what exactly you are asking.
                                      Do you want code to read a file?

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

                                      Aviral 0A 1 Reply Last reply
                                      0
                                      • Aviral 0A Aviral 0

                                        @JonB @jsulm I know it would be frustrating for you both. But Can anyone please write in simple technical terms of what functions I have to use. In a process execution manner?

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by
                                        #19

                                        @Aviral-0
                                        First please answer @jsulm.
                                        Then could you make clear: tail -n and tail -f do somewhat different things. Which of the two's behaviour are you actually looking for?

                                        1 Reply Last reply
                                        0
                                        • jsulmJ jsulm

                                          @Aviral-0 said in The Logs are not showing in Application Window.:

                                          But Can anyone please write in simple technical terms of what functions

                                          Please first clarify what exactly you are asking.
                                          Do you want code to read a file?

                                          Aviral 0A Offline
                                          Aviral 0A Offline
                                          Aviral 0
                                          wrote on last edited by
                                          #20

                                          @jsulm Yes, I want a application which displays Recent 10 Lines of Logs from a Log File. And it should be updating dynamically, any change in log file appears in real time in application window.

                                          Secondly, User be able to pause the Log updates and Be able to select or copy any log lines.

                                          Third, a checkbox filter to filter the application with log types: like If I click on INFO then it should display only INFO logs, similarly for DEBUG and WARN.

                                          The Base version code is this which runs and displays last 10 Logs but is not dynamically updating new logs from file:

                                          #include <QApplication>
                                          #include <QProcess>
                                          #include <QTextEdit>
                                          #include <QVBoxLayout>
                                          #include <QWidget>
                                          
                                          int main(int argc, char *argv[]) {
                                            QApplication app(argc, argv);
                                            QWidget window;
                                            QVBoxLayout layout(&window);
                                            QTextEdit textEdit;
                                            layout.addWidget(&textEdit);
                                            window.show();
                                          
                                            QProcess process;
                                            process.start("tail", QStringList() << "-n" << "10" << "/home/arpitk/QT Projects/logtail1/sample.log");
                                            process.waitForFinished();
                                            QByteArray output = process.readAllStandardOutput();
                                            textEdit.setPlainText(output);
                                          
                                            return app.exec();
                                          }
                                          
                                          
                                          Aviral 0A JonBJ 2 Replies Last reply
                                          0

                                          • Login

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