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. [pyside] Implement a "tail -f" solution using QTextBrowser
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.7k 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
    martinbach
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      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
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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
        0
        • M Offline
          M Offline
          martinbach
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            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
            0

            • Login

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