Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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 ?



  • 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.


  • Lifetime Qt Champion

    Hi,

    What about QProcess ?



  • 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]



  • 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


Log in to reply