Results 1 to 3 of 3

Thread: Flush buffer for QProcess in PyQt5

  1. #1
    Join Date
    Nov 2016
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question Flush buffer for QProcess in PyQt5

    Hi everyone!

    I have a Python 3.4 app using the PyQt5 framework and I'm having an issue.

    I setup a QProcess:

    Qt Code:
    1. def listenToServer(self, MainWindow):
    2. self.ws = QtCore.QProcess(self)
    3. self.ws.start("python3 /home/pi/scara_panel/ws.py")
    4. self.ws.readyReadStandardOutput.connect(self.processServer)
    To copy to clipboard, switch view to plain text mode 

    And it calls this function:

    Qt Code:
    1. def processServer(self):
    2. income = str(self.ws.readAllStandardOutput())
    3. print(income)
    To copy to clipboard, switch view to plain text mode 

    On a desktop, it works fine. It flows into to the app. However, when the program is run on a Raspberry Pi, it only displays what its read once the script ws.py terminates.

    I've read that this has to do with output buffering in Python. I've tried things like adding the -u flag, but no dice. Any suggestions on how to clear this buffer when using readAllStandardOutput()?

    I've tried implementing a few things from http://stackoverflow.com/questions/1...tput-buffering but nothing seems to fix the issue.

    Any help is appreciated!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,403
    Thanks
    37
    Thanked 1,542 Times in 1,493 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Flush buffer for QProcess in PyQt5

    Strange, as usually there is very little to no difference between running on desktop Linux and on embedded Linux, especially on the Pi as this is often desktop Linux, just for ARM (e.g. Rasphian).

    Have you tried the "-u" switch with the better QProcess start() overload?
    The one that takes the program to run and the arguments as a list?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    hannahpatellis (4th November 2016)

  4. #3
    Join Date
    Nov 2016
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Flush buffer for QProcess in PyQt5

    Quote Originally Posted by anda_skoa View Post
    Strange, as usually there is very little to no difference between running on desktop Linux and on embedded Linux, especially on the Pi as this is often desktop Linux, just for ARM (e.g. Rasphian).

    Have you tried the "-u" switch with the better QProcess start() overload?
    The one that takes the program to run and the arguments as a list?

    Cheers,
    _
    That did the trick! Thank you so much, I can't believe I hadn't thought of that!

Similar Threads

  1. PyQt5 QTextEdit limiting buffer
    By blissend in forum Newbie
    Replies: 1
    Last Post: 6th November 2015, 21:08
  2. QDataStream and flush()
    By tuli in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2013, 20:57
  3. How to flush a QPainter in Qt 4?
    By choucete in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2009, 11:18
  4. flush draw events
    By rbp in forum Qt Programming
    Replies: 7
    Last Post: 19th March 2009, 09:14
  5. Qprocess buffer to small?
    By xtreme in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2008, 08:11

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.