2

I'm building a simple GUI in PyQt5 which offers the user a few buttons to run functions. Each function is fairly complex and prints out information, including a running and constantly updating percent progress value.

Under normal operation, as the user clicks a button, the process runs and the terminal is constantly updated as expected.

However, I'd like to display this printed information in my GUI, rather than the terminal. I have implemented this using an Emitting Stream to pipe stdout to a ListWidget (after: RealTime output from a subprogram to stdout of a pyQT Widget)

However, my problem is that with PRINT commands redirected to the GUI, it only updates once all function calls have finished executing.

How can I fix this please? I've searched quite a lot for solutions and wonder if QThreads are a solution. However, the functions which print out information are part of a separate module and hence, I'm not sure how to implement a solution using signals or slots or threads etc....

All suggestions greatly appreciated thanks.

Community
  • 1
  • 1
IanRoberts
  • 2,846
  • 5
  • 26
  • 33
  • 1
    There is a nice example here: http://stackoverflow.com/questions/21071448/redirecting-stdout-and-stderr-to-a-pyqt4-qtextedit-from-a-secondary-thread – ImportanceOfBeingErnest Nov 10 '16 at 00:08
  • Thanks for the comment. That post is useful, but I wonder if it's still best practice with respect to PyQt5. I thought that QT5 significantly changed slots and signals, replacing older conventions using decorators like @pyqtSlot()? – IanRoberts Nov 10 '16 at 11:47
  • Pyqt4 mainly dropped older signals & slots techniques http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#old-style-signals-and-slots. The ones used in the example however are up to date and should work in PyQt5 as well. The `pyqtSlot` decorator is not necessary in the linked answer - but doesn't harm either. – sebastian Nov 10 '16 at 13:09
  • @sebastian Decorating with `pyqtSlot` is recommended so that you don't accidentally fall prey to the issue described [here](http://stackoverflow.com/q/20752154/1994235). – three_pineapples Nov 10 '16 at 21:01
  • Thanks for the comments. I'm not sure the suggested solution suits my problem though: ideally, I don't want to create a new QObject class for the function and I want the main GUI to wait until the called function finishes and returns data. In this wait time, I do want the GUI to update however. Is this possible? – IanRoberts Nov 10 '16 at 21:29

0 Answers0