0
votes

I'm new to handling lambda functions in a qprocess signal-slot environment. I'm having a problem with the parameters of the function. In particular with the finished() signal. According to the documentation, it accepts two parameters: def finished (exitCode, exitStatus)

I'm trying somerhing like this:

for i, thing in enumerate(something):
    self.proc_codificar.append(Qprocess())
    #(code here)
    self.proc_codificar[i].finished.connect(lambda exitCode, exitStatus, proc=self.proc_codificar[i]: self.codificar_fin(exitCode, exitStatus, proc))
    #(code here)

And on process finished I want to know exitCode, exitStatus, and the process itself

def self.proc_codificar(self, exitCode, exitStatus, proc)
    print(exitCode)
    print(exitStatus)
    print(proc)

But this way is not working. What is the correct way to handle the lambda function?

1

1 Answers

1
votes

The finished signal of QProcess in PySide2 is overload so there are 2 signatures(see docs):

  • PySide2.QtCore.QProcess.finished(exitCode, exitStatus)

  • PySide2.QtCore.QProcess.finished(exitCode)

Note: The second method is marked as deprecated so in the next versions it could be eliminated.

Given the above, you must indicate the signature in the connection:

for i, thing in enumerate(something):
    process = QProcess()
    # (code here)
    process.finished[int, QProcess.ExitStatus].connect(
        lambda exitCode, exitStatus, proc=process: self.codificar_fin(
            exitCode, exitStatus, proc
        )
    )
    # (code here)
    self.proc_codificar.append(process)

Note: In PyQt5 and Qt/C++ this does not happen.