PDA

View Full Version : QProcess::pid() gives invalid data



shaolin
25th July 2011, 12:12
Hi guys,

I have a strange problem. I'm doing a gui for ffmpeg, and I start ffmpeg using qprocess from within my program. It works nice, but while it's encoding I want to get ffmpeg process pid. If I try to use
QProcess::pid() it gives me some random strings taken from the gui, I think it reads some invalid memory region.
How can I solve this?
Please note that I try to get the pid after the started() signal is emitted and if
qprocess::state() gives me "Running" and while ffmpeg is encoding, so I am 100% sure that the process is running.

Any idea?

Thx in advance

high_flyer
25th July 2011, 18:26
On what platform are you? windows?
If so:

typedef Q_PID

Typedef for the identifiers used to represent processes on the underlying platform. On Unix and Symbian, this corresponds to qint64; on Windows, it corresponds to _PROCESS_INFORMATION*.



typedef struct _PROCESS_INFORMATION {
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId; //<- this is what you are after I guess.
DWORD dwThreadId;
} PROCESS_INFORMATION, *LPPROCESS_INFORMATION;

shaolin
25th July 2011, 23:55
I'm under mac and it should be a typedef qint64, but if I try to prints this value with qdebug() it print a string that is often a piece of the process command line arguments

shaolin
27th July 2011, 10:23
No one can help me?

wysota
27th July 2011, 12:28
Please provide a working minimal example reproducing the problem.

shaolin
27th July 2011, 13:06
... //various declarations
QProcess ffmpeg;
QObject::connect(&ffmpeg, SIGNAL(started()), this, SLOT(getPid()));
ffmpeg.start("ffmpeg -i movie.avi -y movie.mkv"); //just an example. here I call ffmpeg with right parameters to do a (long) encoding

... //getPid() function;

void getPid(){
qdebug() << "FFmpeg pid: " + this.ffmpeg.pid(); //here often it gives me a substring of the command line, let's say for this example "-y mov", but it can happen that it gives me also other strings of my program, like it reads unclean memory
}

//please note that the same piece of code, for other processes I call using QProcess, gives me the right pid

high_flyer
27th July 2011, 13:47
void getPid(){
qdebug() << "FFmpeg pid: " + QString::number(this.ffmpeg.pid()); //here often it gives me a substring of the command line, let's say for this example "-y mov", but it can happen that it gives me also other strings of my program, like it reads unclean memory
}

shaolin
27th July 2011, 14:31
Stupid me, you are absolutely right! Now it works.. sorry for my silly problem..