[pyside] Implement a "tail -f" solution using QTextBrowser
-
wrote on 19 Apr 2014, 14:16 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 ?
-
wrote on 19 Apr 2014, 15:21 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.
-
Hi,
What about QProcess ?
-
wrote on 22 Apr 2014, 07:34 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]
-
wrote on 25 Apr 2014, 03:49 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
5/5