Results 1 to 3 of 3

Thread: pyqt 4: readyReadStandardOutput singal only emits after subprocess completes

  1. #1
    Join Date
    Aug 2009
    Posts
    2
    Qt products
    Platforms
    Windows

    Default pyqt 4: readyReadStandardOutput singal only emits after subprocess completes

    Hello,

    I'm new to Qt and I'm trying to redirect the stdout/stderr from a python script to a TextBroswer window. The problem I'm having is that it seem like the readyReadStandardOutput singal only emits after subprocess completes. I would like it to emit whenever there is new data so it looks like it updated in real-time as the script runs.

    here's some code snipets:


    def runScript(self):
    process = QProcess()
    self.RunningProcess = process
    self.RunningProcess.setProcessChannelMode(QProcess .MergedChannels)
    self.RunningProcess.closeWriteChannel()
    command = "C:\\Python25\\python.exe TestOptparse.py"
    self.connect(self.RunningProcess, SIGNAL("readyReadStandardOutput()"), self.readOutput)
    self.connect(self.RunningProcess, SIGNAL("readyReadStandardError()"), self.readOutput)
    self.RunningProcess.start(command)

    def readOutput(self):
    string = ""
    bytearray = self.RunningProcess.readAllStandardOutput()

    if not bytearray.isEmpty():
    string = str(QString(bytearray))

    self.LoggerWidget.append(string)

    Please help!!

    Francis

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: pyqt 4: readyReadStandardOutput singal only emits after subprocess completes

    readyReadStandardOutput singal only emits after subprocess completes
    .. i once faced this problem ..

    it's a problem of an incorrectly setup buffering method... and
    you won't be able to solve this from within your calling program.
    Either "patch" the program you are calling to use line buffering --
    setlinebuf(stdout) -- or use fflush(stdout) every now and then in this
    program. If you can't do this, then there's no way to solve it.

    It's NOT a problem of QProcess or anything you could solve by any trickery
    here... I have similar issues with some of the programs that I call from some
    of my apps and there's no way around it (at least no platform independent
    one).
    ex: i am using linux to run an external system call glxgears in QProcess and i get output after ten minutes only or when the buffer filled completly ..
    i try this one "glxgears | less" and find the problem in buffer flush
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Aug 2009
    Posts
    2
    Qt products
    Platforms
    Windows

    Default Re: pyqt 4: readyReadStandardOutput singal only emits after subprocess completes

    Thank You! That helped a lot. If somebody else has this problem with Python script processes, you can look here for the solution.

    http://stackoverflow.com/questions/1...tput-buffering

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.