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. Using QPlainTextEdit as a log viewer
Forum Updated to NodeBB v4.3 + New Features

Using QPlainTextEdit as a log viewer

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.4k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bharath144
    wrote on 8 Aug 2014, 06:24 last edited by
    #1

    Hello,

    I have a log viewer dialog which has a QPlainTextEdit to show the output of a process (which is going into a file). I open the file in the log viewer class (keep it open as long as the log viewer object lives) using QFile. I have a QTextStream and I set the QFile to this QTextStream. I then have timer for every 5 seconds and when that expires, I read until end of the stream, append the text I have read to the QPlainTextEdit, save the last read position from the stream and start the timer again.

    The process logs a lot of messages into the file, as the number of messages grow, my log viewer hangs when trying to update the QPlainTextEdit.

    Is my approach to display a log window wrong?
    Can I redirect the output of the QProcess to the QPlainTextEdit? (I set the setStandardOutputFile and setStandardErrorFile)
    In my approach is QTextStream unable to handle the inflow of log messages?

    Any help would be appreciated.

    Regards,
    Bharath

    Cheers!
    ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
    Bharath Narayan M G

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msue
      wrote on 8 Aug 2014, 06:45 last edited by
      #2

      @1) You should make sure that you really only add text and not always replace the whole contents which consistently grows.

      @2) You could start the process keeping the process object and connect to its readyReadStandardOutput and readyReadStandardError signals and on each incoming signal append readAllStandardOutput()and readAllStandardError() to the logger.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bharath144
        wrote on 8 Aug 2014, 09:07 last edited by
        #3

        bq. @1) You should make sure that you really only add text and not always replace the whole contents which consistently grows.

        This is what I am doing. I append only the new content to the QPlainTextEdit, I don't replace the whole thing.

        bq. @2) You could start the process keeping the process object and connect to its readyReadStandardOutput and readyReadStandardError signals and on each incoming signal append readAllStandardOutput()and readAllStandardError() to the logger.

        I am going to try this now.

        Cheers!
        ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
        Bharath Narayan M G

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 8 Aug 2014, 12:32 last edited by
          #4

          Do you incrementally read the contents of the file or reading all the contents of the file every time and dump entire content ? It is better if you keep the track incremental read and append only what is required.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bharath144
            wrote on 8 Aug 2014, 13:04 last edited by
            #5

            bq. Do you incrementally read the contents of the file or reading all the contents of the file every time and dump entire content ? It is better if you keep the track incremental read and append only what is required.

            What I had done initially is to open the file, assign the file to a text stream. I read until the end of the stream, record the position, close the file. After a time out, I opened the file again, seek to the recorded position in the stream, read from there until end. I know that this isn't the effective way as the amount of time taken to open file, seek to a given position in the stream would grow exponentially as the file size increases.

            Cheers!
            ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
            Bharath Narayan M G

            1 Reply Last reply
            0

            1/5

            8 Aug 2014, 06:24

            • Login

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