Results 1 to 7 of 7

Thread: suspending a QProcess

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default suspending a QProcess

    I am trying to suspend a Qprocess and thought about using a function linked to a toolButton that toggles
    Qt Code:
    1. if (pause)
    2. calcProcess->waitForBytesWritten(-1);
    3. else
    4. {
    5. char buf[8];
    6. buf[0]='\0';
    7. calcProcess->write(buf, 8);
    8. }
    To copy to clipboard, switch view to plain text mode 
    I hoped waitForBytesWritten might suspend the Qproces until I write some bytes to it. The proces doesn't take any writing BTW, it only emits character.
    Is there a way to do this?
    I could implement the proces in a QThread but suspening the thread would not suspend the process, or would it?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: suspending a QProcess

    On a posix system, send the suspend signal (SIGTSTP) and continue signal (SIGCONT)

    WaitForBytesWritten blocks till some data has been written to the process.

  3. #3
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: suspending a QProcess

    ok, how do I do that (new to Qt)?
    Can I link this to a toolbutton

    connect(toolButton_pauserun, SIGNAL(SIGTSTP),this, ????);

    or
    connect(toolButton_pauserun, SIGNAL(toggled(bool)), this, SLOT(suspendModel(bool)));
    and in suspendModel

    emit SIGNAL(SIGTSTP);

    how do I the QProcess to receive this?
    thanks
    Last edited by qt_gotcha; 13th August 2010 at 14:39.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: suspending a QProcess

    No, that is not correct.

    I'm talking about system signals. Not Qt signals. This is something completely different. And this is highly system specific. This won't work on Windows for example!

    Use the following commands
    Qt Code:
    1. kill -s SIGTSTP thePIDofYourProgram
    2. kill -s SIGCONT thePIDofYourProgram
    To copy to clipboard, switch view to plain text mode 

    One thing I do need to say:
    This technique shouldn't be used when you can build a pause option into the program being run by QProcess. But if the program being used is closed source and doesn't provide a pause option, you have no choice

    Edit: And I'm sure data corruption can happen when using this technique, so be careful and read as much as you can about it.

  5. #5
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: suspending a QProcess

    thanks, but that is outside my scope
    on the other hand the process information has a handle to the main thread of the process which can then be suspended (that's how I did it in borland). in windows:
    typedef struct _PROCESS_INFORMATION {
    HANDLE hProcess;
    HANDLE hThread; <======
    DWORD dwProcessId;
    DWORD dwThreadId;
    }

    found it:
    Qt Code:
    1. #include <windows.h>
    2.  
    3. void nutshellqt::suspendModel(bool pause)
    4. {
    5. PROCESS_INFORMATION *pi = calcProcess->pid();
    6.  
    7. if (pause)
    8. {
    9. SuspendThread(pi->hThread);
    10. }
    11. else
    12. {
    13. ResumeThread(pi->hThread);
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 
    of ocurse only windows, for unix something else would have to be implemented. but for now this will do
    Last edited by qt_gotcha; 13th August 2010 at 15:31.

  6. #6
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: suspending a QProcess

    If all you want to do is stop reading, you can also close the read channel. The process will still run in the background, but you will not receive any data.

  7. #7
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: suspending a QProcess

    sorry for editing my reply while you are answering.
    I want the actual proces to suspend. In any case thanks for your help

Similar Threads

  1. [Newbie]: Suspending the main GUI thread
    By abhinavc in forum Newbie
    Replies: 3
    Last Post: 16th May 2010, 21:41
  2. QMainWindow Dragging is suspending QTimer
    By zaferaltug in forum Qt Programming
    Replies: 3
    Last Post: 10th February 2009, 13:23
  3. QProcess inside QProcess
    By bunjee in forum Qt Programming
    Replies: 7
    Last Post: 4th December 2008, 00:39
  4. QProcess cmd
    By Nykoo in forum Qt Programming
    Replies: 1
    Last Post: 31st March 2008, 10:50
  5. Qprocess Help
    By IsleWitch in forum Newbie
    Replies: 2
    Last Post: 10th October 2007, 13:04

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.