Skip to content Skip to sidebar Skip to footer

Communicating With Qprocess Python Program

I'm trying to get a Qt application to communicate with a python program. The most logical solution seemed to be to run a QProcess in the Qt app containing the Python code. I want t

Solution 1:

The problem appears to be the way in which python buffers stdout (it's not line buffered). The code you posted works for me if I change the script to...

#!/usr/bin/env python2
import os
import sys
import timewhile True:
    print"test"
    sys.stdout.flush()
    time.sleep(2)

There's probably a better way to achieve the same thing without having to explicitly flush the stream constantly.

Alternatively, if you are on Linux, you could use stdbuf to control the output buffering of the script. Change the process start command to...

process->start("stdbuf", QStringList() << "--output=L" << "/home/user/test.py");

Post a Comment for "Communicating With Qprocess Python Program"