Qt Forum

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

    [pyside] Implement a "tail -f" solution using QTextBrowser

    General and Desktop
    3
    5
    1436
    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
      martinbach last edited by

      I'd like to show on my QTextBrowser the current content of a log text file (i.e. /var/log/syslog) like I usually use to see when typing "tail -f /var/log/syslog" on a terminal.

      Is there a way to obtain such a result on a QTextBrowser ?

      @def tail_syslog(self):
      filename = '/var/log/syslog'
      f = subprocess.Popen(['tail','-F',filename], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
      p = select.poll()
      p.register(f.stdout)

          while True:
              if p.poll(1):
                  self.textBrowser_SYSLOG.insertPlainText(f.stdout.readline())
      

      print f.stdout.readline()

              time.sleep(1)
      

      @

      If I use something like the above code my MainWindows doesn't show anymore.

      Could you help me ?

      1 Reply Last reply Reply Quote 0
      • A
        andreyc last edited by

        tail_syslog(self) does not return control to Qt. If it is running in a main thread then Qt does not have a chance to display anything.

        I would suggest to run tail_syslog() in separate thread and emit a signal each time when new data arrived. Catch this signal a main thread and display data that comes whith the signal.

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          What about QProcess ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • M
            martinbach last edited by

            Do you have any link where I can study more about what you suggest ?
            I'm really a newby.

            [quote author="andreyc" date="1397920871"]tail_syslog(self) does not return control to Qt. If it is running in a main thread then Qt does not have a chance to display anything.

            I would suggest to run tail_syslog() in separate thread and emit a signal each time when new data arrived. Catch this signal a main thread and display data that comes whith the signal.[/quote]

            1 Reply Last reply Reply Quote 0
            • A
              andreyc last edited by

              Frankly speaking I don't know. Just copule articles that I've read about QThread.
              "Here":http://qt-project.org/wiki/Threads_Events_QObjectsis
              Another "good article on QThread":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

              And of course the books.
              Although most of the "books":http://qt-project.org/books are for Qt4 there is no big changes in QThread between Qt 4 and 5

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