Results 1 to 8 of 8

Thread: QProcess::pid() gives invalid data

  1. #1
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default QProcess::pid() gives invalid data

    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
    Qt Code:
    1. QProcess::pid()
    To copy to clipboard, switch view to plain text mode 
    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
    Qt Code:
    1. qprocess::state()
    To copy to clipboard, switch view to plain text mode 
    gives me "Running" and while ffmpeg is encoding, so I am 100% sure that the process is running.

    Any idea?

    Thx in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess::pid() gives invalid data

    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*.
    Qt Code:
    1. typedef struct _PROCESS_INFORMATION {
    2. HANDLE hProcess;
    3. HANDLE hThread;
    4. DWORD dwProcessId; //<- this is what you are after I guess.
    5. DWORD dwThreadId;
    6. } PROCESS_INFORMATION, *LPPROCESS_INFORMATION;
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess::pid() gives invalid data

    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

  4. #4
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess::pid() gives invalid data

    No one can help me?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess::pid() gives invalid data

    Please provide a working minimal example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess::pid() gives invalid data

    Qt Code:
    1. ... //various declarations
    2. QProcess ffmpeg;
    3. QObject::connect(&ffmpeg, SIGNAL(started()), this, SLOT(getPid()));
    4. ffmpeg.start("ffmpeg -i movie.avi -y movie.mkv"); //just an example. here I call ffmpeg with right parameters to do a (long) encoding
    5.  
    6. ... //getPid() function;
    7.  
    8. void getPid(){
    9. 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
    10. }
    11.  
    12. //please note that the same piece of code, for other processes I call using QProcess, gives me the right pid
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QProcess::pid() gives invalid data

    Qt Code:
    1. void getPid(){
    2. 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
    3. }
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. The following user says thank you to high_flyer for this useful post:

    shaolin (27th July 2011)

  9. #8
    Join Date
    Nov 2010
    Posts
    27
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QProcess::pid() gives invalid data

    Stupid me, you are absolutely right! Now it works.. sorry for my silly problem..

Similar Threads

  1. Replies: 0
    Last Post: 26th August 2010, 10:44
  2. Reading lots of Data from QProcess without freezing
    By nightghost in forum Qt Programming
    Replies: 12
    Last Post: 27th January 2010, 08:23
  3. QProcess and reading data from xterm
    By sawerset in forum Qt Programming
    Replies: 0
    Last Post: 9th February 2009, 20:48
  4. recieving QProcess::write data
    By node_ex in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2008, 12:18
  5. Replies: 2
    Last Post: 12th September 2007, 07:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.