Spencer
Spencer

Reputation: 2110

get pid of finished QProcess

I'm trying to get the PID of a finished QProcess, something like this:

proc = QProcess.start()
proc.finished.connect(self.finished)

def finished(self):
    self.sender().pid()

QProcess.pid() will return 0 if the process is closed however, and QProcess.finished() would only call once the process is complete, so I can only ever get 0... How can I work around this? I'm trying to think of a way to NOT have to use the PID on completion, but at the moment that's what I have to do.

I tried proc.aboutToClose.connect(self.finished) but this never returned anything so it seems it wasn't signaled, but that would be a good solution if I can get that to work.

Upvotes: 0

Views: 933

Answers (1)

Spencer
Spencer

Reputation: 2110

Ekhumoro gave the answer, the solution is to name the process by the PID and therefore you can still get it later by just querying the object name:

proc.setObjectName(str(proc.pid()))

Upvotes: 1

Related Questions