Results 1 to 8 of 8

Thread: QProcess in qt-2.3

  1. #1
    Join Date
    May 2008
    Posts
    21
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default QProcess in qt-2.3

    I want to run external program in my app (using qt-2.3), but there is no qprocess class in my qt version.
    Is there any idea how to execute external program in qt-2.3?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess in qt-2.3

    You can use standard C calls for that (assuming you have an OS).

  3. #3
    Join Date
    May 2008
    Posts
    21
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QProcess in qt-2.3

    Now, I'm using popen() function to run program, but it seemed like I can't stop that running program.
    I've tried using pclose(), but it didn't work.
    Can u tell me how to stop it?

    regards,

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess in qt-2.3

    pclose() just waits for the application to stop. If you can't convince that application to quit by talking to it through the pipe, you will have to signal it using kill() but for this you need its PID. I don't know if there is a reliable way to get a PID of a child process created with popen(), but you can always use fork+exec combo instead of popen().

  5. #5
    Join Date
    May 2008
    Posts
    21
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QProcess in qt-2.3

    Thank you..
    I'm using fork+exec now, b'cause when i used popen my program hang up.
    But the problem now I still can't kill the child process which I've made.
    This is my source code to kill a child process:

    pid_t pid;
    pid = getpid();
    kill(pid,0);

    When I ran it after I created child process, my program ended, it seemed that I've also killed the parent process.
    Do you have any idea?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess in qt-2.3

    Quote Originally Posted by winarko View Post
    When I ran it after I created child process, my program ended, it seemed that I've also killed the parent process.
    Not "also" --- you kill the parent process. getpid() returns the PID of current process, so you have to use the PID returned by fork() instead.

  7. #7
    Join Date
    May 2008
    Posts
    21
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QProcess in qt-2.3

    really?
    so,how can i get pid created by fork and kill it?

    thx.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess in qt-2.3

    Quote Originally Posted by winarko View Post
    how can i get pid created by fork and kill it?
    In parent process fork() returns PID of the child process.
    Qt Code:
    1. pid_t pid = fork();
    2. if( pid == 0 ) {
    3. // child process
    4. }
    5. else if( pid > 0 ) {
    6. // parent process
    7. // pid == child's PID
    8. }
    9. else {
    10. // fork failed (parent process)
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QProcess exitStatus()
    By user_mail07 in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2008, 20:51
  2. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  3. QProcess extremely slow on Windows?
    By Pepe in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2007, 00:25
  4. problem with qprocess
    By deekayt in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 13:30
  5. QProcess in a QThread
    By chombium in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2006, 15:52

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
  •  
Qt is a trademark of The Qt Company.