I have a a Main window wrapper class (Say A) and another class used in the wrapper (say B). B has a method that in turn HAD a subrocess.check_call(command) call. I'm changing it to use QProcess in order to be able to communicate with this process and display the Qprocess stdout and stderr in main window QTextEdit as well send back data to Qprocess stdin from main window QLineEdit.
for that I have:
class A(....):
def __init__(self):
....
QtCore.QObject.connect(self.ui.actionNew, QtCore.SIGNAL("triggered()", self.selectedNew)
self.qprocess = QtCore.QProcess()
self.connect(self.qprocess, QtCore.SIGNAL("readyReadStandardOutput()", self.readStdOut)
self.connect(self.qprocess, QtCore.SIGNAL("readyReadStandardError()", self.readStdErr)
def readStdOut(self):
self.ui.text_edit.append(QtCore.QString(self.qprocess.readAllStandardOutput()))
def readStdErr(self):
self.ui.text_edit.append(QtCore.QString(self.qprocess.readAllStandardError()))
def selectedNew(self:)
...
newB = B(self.qprocess)
newB.doWork(params)
class B():
def __init__(self, qprocess):
self.qp = qprocess
def doWork(params):
...
# creating a thread to not block the main thread
class ConsoleThread(threading.Thread):
def __init__(self, qprocess):
self.tqp = qprocess
threading.Thread.__init__(self)
def run(self):
self.qtp.execute("script_that_waits_for_user_input_during_execution")
# starting the thread and passing it the QProcess instance from B
ConsoleThread(self.qp).start()
print(self.qp.state()) # this returns 0, when I expected 2, obviously something wrong
in the end the output of the "script_that_waits_for_user_input_during_execution" is not showing up in QTextEdit, but is still printed in the console. It doesn't seem that I'm getting any signals back in A and I'm not reaching A.readStdOut() method. General idea is to have a GUI app wrapping different command line scripts. So i need a way to correctly get the output from the QProcess and be able to communicate back by writing to it from GUI. Of course it could probably be less complicated if i would move the functions from B to A (would eliminate unnecessary steps) but in the same time GUI wrapper should be separate from logic i think.
Thanks!